高净值什么意思| 什么颜色最防晒| 甲亢在中医里叫什么病| 天津是什么省| landrover是什么车| 脸肿挂什么科| 皮肤擦伤用什么药膏| 72年是什么年| 优思悦是什么药| 三月二十八号是什么星座| 女人阴虚是什么意思| 养猫的人容易得什么病| 白带是什么样的| 同房肚子痛是什么原因| 做蛋糕用什么面粉| 腿上无缘无故出现淤青是什么原因| 喵喵喵是什么意思| 1月13是什么星座| 怀孕了不想要最好的办法是什么| 一贫如什么| 着凉嗓子疼吃什么药| 鸡蛋壳属于什么垃圾| 咳嗽是什么原因引起的| 免疫球蛋白e高说明什么| 脑电图是什么| 血压突然升高是什么原因| 不打狂犬疫苗会有什么后果| 红薯什么时候掐尖| 中药什么时间喝效果最好| 一个米一个参念什么| 奥美拉唑什么时候吃最好| 团长是什么军衔| 胆道闭锁有什么症状| 弱阳性是什么原因| 茼蒿不能和什么一起吃| 什么的世界| 石男是什么意思| 马瘦毛长是什么意思| 说什么| 包粽子用什么叶子| 怀孕上火吃什么能降火| 白癜风的症状是什么| 甲状腺回声不均匀什么意思| 太阳最后会变成什么| 吃了鸡蛋不能吃什么| 熬是什么意思| 正三角形是什么| 具象是什么意思| 男朋友生日送什么礼物| 撸是什么意思| 近水楼台是什么意思| 吃了发芽的土豆会有什么症状| 脖子里面有结节是什么病| paul是什么意思| 杭字五行属什么| 素什么意思| tg是什么| b是什么牌子的衣服| 念珠菌性阴道炎有什么症状| 肺部结节是什么引起的| 甲亢是什么回事| 怀孕十天有什么反应| 歇菜是什么意思| 维生素D有什么食物| 大夫古代指什么| 苦瓜汤为什么要放黄豆| 梦到猫是什么意思| 中二是什么意思| 高铁不能带什么| 乙肝病毒是什么| 后背不舒服是什么原因| 肛门瘙痒是什么问题| 吃糖醋蒜有什么好处和坏处| 家里适合养什么鱼| 三九胃泰治什么胃病效果好| 护肝片什么时候吃最好| 类固醇是什么东西| 壬子五行属什么| cheese是什么意思| 男性手心热是什么原因| 对辣椒过敏有什么症状| 长卿是什么意思| ads是什么意思| 肝硬化是什么意思| 9月3号是什么节日| 人心果什么时候成熟| 肝脏钙化灶什么意思| 牙银肿痛吃什么药| 头晕目眩挂什么科| 肢解是什么意思| 1974年属虎是什么命| 16岁属什么| 多囊为什么要吃避孕药| 什么是云母| 发烧可以吃什么水果| 为什么不孕不育| 多囊什么意思| 白皮书是什么意思| 氩弧焊对身体有什么危害| 市级三好学生有什么用| 三合生肖是什么意思| 钙片不能和什么一起吃| 慢性萎缩性胃炎吃什么药| 吃鱼肝油有什么好处| 外阴红肿瘙痒用什么药| 打嗝是什么病| 缺席是什么意思| 指鹿为马指什么生肖| 猕猴桃和什么榨汁好喝| 什么是四环素牙| 肺炎吃什么水果好| 术后吃什么水果| 毛孔粗大用什么洗面奶好| 吃什么油最健康排行榜| 石男是什么意思| olp是什么意思| 肌无力有什么症状| 胎儿颈部可见u型压迹什么意思| 淤青用什么药| 认贼作父是什么意思| 庙是什么意思| 含锶矿泉水有什么好处| 血糖高喝什么茶好| 胸腔积液是什么原因引起的| 什么鱼吃泥鳅| 心态是什么意思| 窥见是什么意思| 运动后喝什么饮料最好| 花菜炒什么好吃| 主张是什么意思| 为什么吃饱了就犯困| 小狗感冒症状是什么样的| nb什么牌子| 梦见朋友怀孕了是什么意思| 梦见把狗打死了是什么意思| 尿液中粘液丝高是什么原因| darling是什么意思| 为什么故宫龙椅坐不得| 夏季喝什么茶好| 一般什么意思| 检查膝盖挂什么科| 心率低有什么危害| 老公护着婆婆说明什么| 金字旁加者念什么| 皇帝自称什么| ssa抗体阳性说明什么| 肌酐偏低是什么意思| 1975年属兔五行属什么| 一什么冰箱| 珊瑚绒是什么面料| 广州的市花是什么| 北京户口有什么用| 家庭长期饮用什么水最好| 老年人骨质疏松吃什么钙片好| 8月是什么季节| 炊饼是什么| 赤茯苓又叫什么| 夭折是什么意思| vos是什么意思| 耳朵尖的人什么命| 补充镁有什么好处| 眼袋大是什么原因| 二十岁是什么之年| 肠胃炎引起的发烧吃什么药| 舌头痛吃什么药好| 火把节是什么时候| 孔雀吃什么食物| 一号来的月经排卵期是什么时候| 工作是什么意思| 什么是自由度| 微商是什么意思| 98年属什么的| 马黛茶什么味道| 眼睛不能见光是什么病| 滞后是什么意思| 荞麦和苦荞有什么区别| 冶阳萎什么药最有效| pisen是什么牌子| 浩浩荡荡是什么意思| 德艺双馨是什么意思| 怡字五行属什么的| 金翅鸟吃什么| 什么是人工智能| 干涸是什么意思| 代谢不好是什么原因| 触霉头是什么意思| 脾虚湿盛吃什么中药| 皮炎是什么原因引起的| 貔貅和麒麟有什么区别| 孕妇梦见下雪是什么征兆| 法国的国鸟是什么| 七月与安生讲的是什么| 双字五行属什么| 上皮细胞是什么意思| ctu是什么意思| 手足口病吃什么药好得快| 口臭口苦口干吃什么药| 总胆固醇高忌口什么| 开救护车需要什么条件| 婴儿湿疹用什么药膏最有效| 香菇不能和什么一起吃| 纸上谈兵是什么生肖| 冠心病什么症状表现| 闪失是什么意思| 强迫症吃什么药| 属鼠的是什么命| 前胸贴后背是什么意思| 五险都有什么险| mk是什么牌子| 春晓描写的是什么季节| 碱水对人有什么危害| 心理学属于什么学科| 尿道感染吃什么药好得快| 红红火火是什么生肖| 合拍是什么意思| 水晶粉是什么原料做的| 感冒可以吃什么水果好| 减肥早餐吃什么| 士多啤梨是什么水果| 什么是电解质饮料| 二十二岁属什么| 湿热吃什么药好| 脾切除后有什么影响| 龙王庙是指什么生肖| 看手指甲挂什么科室| 鸡肉与什么食物相克| 胆红素高说明什么| gpt是什么| 喘不过气是什么原因| 胸腔积液是什么意思| 维生素b吃什么| 时柱代表什么| 士大夫什么意思| 精虫上脑是什么意思| 敏感肌是什么样的| 松香是什么| 鼻子出油多是什么原因| 未加一笔是什么字| 介入科主要看什么病| 婴幼儿积食会有什么症状| 为什么会长胎记| 世界之大无奇不有是什么意思| 金枝玉叶什么生肖| 头发分叉是什么原因| 阅历是什么意思| 打喷嚏流清鼻涕属于什么感冒| 小气是什么意思| 青春永驻什么意思| 雨花斋靠什么盈利| 后生可畏是什么意思| 慢性活动性胃炎是什么意思| 什么食物补锌效果最好| 你好是什么意思| 柠檬可以做什么| 血铅是什么| 不以规矩下一句是什么| 算理是什么意思| 维生素b2有什么功效| few是什么意思| 胸有成竹什么意思| 什么植物驱蚊效果最好| 脱发吃什么药| 眉尾上方有痣代表什么| 帕金森病是什么病| 百度Jump to content

研究显示:太依赖卫星导航功能将让大脑导航功能退化

From Wikipedia, the free encyclopedia
百度 雅虎日本将通过其子公司YJFX购买BitARG的股票。

The most vexing parse is a counterintuitive form of syntactic ambiguity resolution in the C++ programming language. In certain situations, the C++ grammar cannot distinguish between the creation of an object parameter and specification of a function's type. In those situations, the compiler is required to interpret the line as the latter.

Occurrence

[edit]

The term "most vexing parse" was first used by Scott Meyers in his 2001 book Effective STL.[1] While unusual in C, the phenomenon was quite common in C++ until the introduction of uniform initialization in C++11.[2]

Examples

[edit]

C-style casts

[edit]

A simple example appears when a functional cast is intended to convert an expression for initializing a variable:

void f(double my_dbl) {
  int i(int(my_dbl));
}

Line 2 above is ambiguous. One possible interpretation is to declare a variable i with initial value produced by converting my_dbl to an int. However, C allows superfluous parentheses around function parameter declarations; in this case, the declaration of i is instead a function declaration equivalent to the following:

// A function named i takes an integer and returns an integer.
int i(int my_dbl);

Unnamed temporary

[edit]

A more elaborate example is:

struct Timer {};

struct TimeKeeper {
  explicit TimeKeeper(Timer t);
  int get_time();
};

int main() {
  TimeKeeper time_keeper(Timer());
  return time_keeper.get_time();
}

The line

  TimeKeeper time_keeper(Timer());

is ambiguous, since it could be interpreted either as

  1. a variable definition for variable time_keeper of class TimeKeeper, initialized with an anonymous instance of class Timer or
  2. a function declaration for a function time_keeper that returns an object of type TimeKeeper and has a single (unnamed) parameter, whose type is a (pointer to a) function[Note 1] taking no input and returning Timer objects.

The C++ standard requires the second interpretation, which is inconsistent with the subsequent line 10 above. For example, Clang++ warns that the most vexing parse has been applied on line 9 and errors on the subsequent line 10:[3]

$ clang++ time_keeper.cc
timekeeper.cc:9:25: warning: parentheses were disambiguated as a function declaration
      [-Wvexing-parse]
  TimeKeeper time_keeper(Timer());
                        ^~~~~~~~~
timekeeper.cc:9:26: note: add a pair of parentheses to declare a variable
  TimeKeeper time_keeper(Timer());
                         ^
                         (      )
timekeeper.cc:10:21: error: member reference base type 'TimeKeeper (Timer (*)())' is not a
      structure or union
  return time_keeper.get_time();
         ~~~~~~~~~~~^~~~~~~~~

Solutions

[edit]

The required interpretation of these ambiguous declarations is rarely the intended one.[4][5] Function types in C++ are usually hidden behind typedefs and typically have an explicit reference or pointer qualifier. To force the alternate interpretation, the typical technique is a different object creation or conversion syntax.

In the type conversion example, there are two alternate syntaxes available for casts: the "C-style cast"

// declares a variable of type int
int i((int)my_dbl);

or a named cast:

int i(static_cast<int>(my_dbl));

In the variable declaration example, the preferred method (since C++11) is uniform (brace) initialization.[6] This also allows limited omission of the type name entirely:

//Any of the following work:
TimeKeeper time_keeper(Timer{});
TimeKeeper time_keeper{Timer()};
TimeKeeper time_keeper{Timer{}};
TimeKeeper time_keeper(     {});
TimeKeeper time_keeper{     {}};

Prior to C++11, the common techniques to force the intended interpretation were use of an extra parenthesis or copy-initialization:[5]

TimeKeeper time_keeper( /*Avoid MVP*/ (Timer()) );
TimeKeeper time_keeper = TimeKeeper(Timer());

In the latter syntax, the copy-initialization is likely to be optimized out by the compiler.[7] Since C++17, this optimization is guaranteed.[8]

Notes

[edit]
  1. ^ According to C++ type decay rules, a function object declared as a parameter is equivalent to a pointer to a function of that type. See Function object#In C and C++.

References

[edit]
  1. ^ Meyers, Scott (2001). Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library. Addison-Wesley. ISBN 0-201-74962-9.
  2. ^ Coffin, Jerry (29 December 2012). "c++ - What is the purpose of the Most Vexing Parse?". Stack Overflow. Archived from the original on 17 January 2021. Retrieved 2025-08-06.
  3. ^ Lattner, Chris (5 April 2010). "Amazing Feats of Clang Error Recovery". LLVM Project Blog. The Most Vexing Parse. Archived from the original on 26 September 2020. Retrieved 2025-08-06.
  4. ^ DrPizza; Prototyped; wb; euzeka; Simpson, Homer J (October 2002). "C++'s "most vexing parse"". ArsTechnica OpenForum. Archived from the original on 20 May 2015. Retrieved 2025-08-06.
  5. ^ a b Boccara, Jonathan (2025-08-06). "The Most Vexing Parse: How to Spot It and Fix It Quickly". Fluent C++. Archived from the original on 2025-08-06. Retrieved 2025-08-06.
  6. ^ Stroustrup, Bjarne (19 August 2016). "C++11 FAQ". www.stroustrup.com. Uniform initialization syntax and semantics. Archived from the original on 2025-08-06. Retrieved 2025-08-06.
  7. ^ "Myths and urban legends about C++". C++ FAQ. What is copy elision? What is RVO?. Archived from the original on 17 January 2021. Retrieved 2025-08-06.
  8. ^ Devlieghere, Jonas (2025-08-06). "Guaranteed Copy Elision". Jonas Devlieghere. Archived from the original on 2025-08-06. Retrieved 2025-08-06. Note, however, the caveats covered in Brand, C++ (2025-08-06). "Guaranteed Copy Elision Does Not Elide Copies". Microsoft C++ Team Blog. Archived from the original on 2025-08-06. Retrieved 2025-08-06.
[edit]
脸上长扁平疣是什么原因引起的 客车是什么车 梦到被蛇咬是什么意思 热量是什么意思 蛇肉吃了有什么好处
面试穿什么衣服比较合适 孕妇吃什么补钙 脑梗应该挂什么科 什么异思迁 夏威夷果吃了有什么好处
六月初二是什么日子 预谋是什么意思 2024年属什么年 流水生财是什么意思 下面瘙痒用什么药
舌苔黄厚是什么原因 一什么凤冠 龈颊沟在什么位置图片 有什么奇怪 8月6日是什么星座
乙肝第二针最晚什么时候打hcv9jop6ns6r.cn 孕妇红细胞偏低是什么原因hcv9jop4ns3r.cn 高血脂看什么科liaochangning.com 土崩瓦解是什么意思hcv9jop6ns4r.cn sandisk是什么牌子hcv7jop6ns1r.cn
日本为什么投降hcv8jop2ns0r.cn 什么叫鳞状细胞hcv8jop7ns6r.cn mol是什么意思hcv8jop7ns1r.cn 龋坏是什么意思hcv8jop0ns6r.cn 妊娠反应什么时候开始hcv8jop9ns0r.cn
狗怕什么hcv9jop8ns3r.cn 转述句什么意思hcv9jop5ns5r.cn 晕车喝什么饮料好hcv8jop5ns8r.cn 跳楼是什么感觉hcv9jop1ns2r.cn 办独生子女证需要什么材料ff14chat.com
气虚的人适合什么运动hcv8jop5ns1r.cn 知性女性是什么意思hcv8jop8ns3r.cn 月是什么意思hcv8jop7ns2r.cn 什么泡水喝降甘油三酯hcv7jop5ns1r.cn 月经期吃什么hcv8jop0ns5r.cn
百度