人授和试管有什么区别| 自言自语是什么| kinghome是什么牌子| 生吃胡萝卜有什么好处和坏处| 婚检挂什么科| 丈夫的弟弟叫什么| 肛周脓肿是什么原因引起的| 梦见小白蛇是什么预兆| 什么东西补钙最好最快| 五谷中的菽是指什么| gpt是什么| 茶叶含有什么成分| 胃泌素17是什么检查| 什么水果清热去火| 尿红色是什么原因| 什么叫卒中| 宫颈糜烂吃什么药| 面黄肌瘦是什么意思| 西亚是什么人种| ab是什么| 经验是什么意思| 杭盖是什么意思| 什么品牌的沙发好| 口腔溃疡用什么药| 难道是什么意思| 三斤八两什么意思| feel是什么意思| dave是什么意思| 什么年什么月| 控销药品什么意思| 孔雀开屏是什么行为| 龙女是什么意思| 彩云之南是什么意思| 正山小种是什么茶| 彩头是什么意思| 什么是色盲| 儿童风热感冒吃什么药| 什么是跨境电商| 梦见苹果是什么意思| 心跳过快有什么危害| 切忌什么意思| 磁共振和核磁共振有什么区别| 孩子打呼噜是什么原因| 敲锣打鼓是什么生肖| 副主任医师什么级别| 嘴巴里面起泡是什么原因引起的| 每次睡觉都做梦为什么| 传媒公司是做什么的| 自白是什么意思| 水杨酸有什么作用| 腹部叩诊什么音正常| 牙龈萎缩是什么原因引起的| 日字五行属什么| 晕3d什么症状| 鲜花又什么又什么| 哎一古是什么意思| 明年是什么年啊| 广肚是什么| 卧轨是什么意思| 廉洁奉公是什么意思| 流火是什么原因造成的| 八朵玫瑰花代表什么意思| 梦见翻车是什么预兆| 咳嗽肺疼是什么原因| 女人体检都查什么项目| 孕前检查一般有什么项目| 五月二十八是什么日子| 小蛮腰是什么意思| 三叉神经痛看什么科| 火乐念什么| 啵是什么意思| amc是什么| 前列腺炎吃什么消炎药好| 内啡肽是什么| 血糖高是什么症状| 十二月十四日是什么星座| gap是什么牌子的衣服| 俗气是什么意思| 蛔虫和蛲虫有什么区别| 祖庭是什么意思| 58岁属什么生肖| 精工手表什么档次| 西游记是什么时候写的| 髋关节弹响是什么原因| flour是什么意思| 前兆是什么意思| b-h是什么药| 排骨炖什么比较好吃| 大学辅导员是干什么的| 驱除鞑虏是什么意思| 芒果不可以跟什么一起吃| 腮腺炎吃什么药| 药食同源是什么意思| 春天开的花都有什么花| 凌晨属于什么时辰| 在野是什么意思| 尿妊娠试验是检查什么| 为什么一到晚上就咳嗽| 镇关西是什么意思| 深水炸弹什么意思| 心梗吃什么药| 为什么今年有两个六月| 什么中药补气血效果最好| 咽炎是什么原因引起的| 李小龙和丁佩什么关系| 今年十八岁属什么生肖| 为什么老是犯困| 甲沟炎是什么样子的| 肝结节是什么病严重吗| 偏财代表什么| 热射病是什么| ur品牌属于什么档次| 耳石症看什么科| 自言自语什么意思| 琼瑶是什么意思| 摩羯座女生和什么星座男生最配| 白天梦见蛇是什么预兆| 生产周期是什么意思| 应用化学是干什么的| 泪腺堵塞是什么症状| 这个季节吃什么水果| ricoh什么牌子| 罗非鱼是什么鱼| 米杏色是什么颜色| 长的像蛇的鱼是什么鱼| 心脏下边是什么器官| 长白头发是什么原因| 娇妻是什么意思| 七月七日是什么生肖| 孕期什么时候补充dha| 哭笑不得是什么意思| 十月十三是什么星座| 农历五月初五是什么节| 咖喱块什么牌子的好| 什么是清宫| 羽五行属什么| 乳酸偏高是什么意思| 口腔溃疡吃什么中成药| 血友病是什么| 边界尚清是什么意思| 台湾以前叫什么名字| 祸不单行是什么意思| 缺钾最明显的症状是什么| 此贝是什么字| 胃疼需要做什么检查| 祛痣后应注意什么| 什么是脱脂牛奶| 鸡飞狗跳的意思是什么| 师长是什么意思| 2月15日什么星座| 淘米水洗脸有什么作用与功效| 农转非是什么意思| 心什么胆什么| 瘥是什么意思| 人为什么会打哈欠| 主观意识是什么意思| 肌层回声欠均匀是什么意思| 肌酐高吃什么药好| 汗疱疹用什么药膏最好| 虹字五行属什么| 三净肉是什么| 化石是什么| 过敏痒用什么药膏| 公立医院和私立医院有什么区别| 红沙日是什么意思| 孕妇脚抽筋是什么原因| 下次闰六月是什么时候| 苍蝇馆子什么意思| 羊毛疔是什么病| 熊人是什么意思| 梦见磨面粉是什么意思| 嬷嬷是什么意思| 孕妇梦见棺材是什么征兆| 三个句号代表什么意思| 笑口常开是什么生肖| 可爱的动物是什么生肖| 眼底出血有什么症状| 凌晨十二点是什么时辰| 什么是电离辐射| 感冒不能吃什么| 间隙是什么意思| 小孩咳嗽流鼻涕吃什么药效果好| 乳房长斑点是什么原因| 钱是什么单位| 六块钱麻辣烫什么意思| 婴儿坐高铁需要什么证件| bv是什么品牌| 春宵一刻值千金什么意思| 但愿人长久的下一句是什么| 哈工大全称是什么| 男性孕前检查挂什么科| pro是什么的缩写| 小暑吃什么食物| rarone是什么牌子的手表| 小狗什么时候可以洗澡| 老婆妹妹叫什么| 尿不出来吃什么药| ar是什么元素| 尿酸高吃什么药效果好| mbc是什么意思| 家里出现蟑螂预示什么| 空调制热效果不好什么原因| 减肥为什么不让吃茄子| 前列腺是什么东西| 什么叫腱鞘炎| 熬夜眼睛红血丝用什么眼药水| 甲己合化土什么意思| 窦骁的父母是干什么的| 萎缩性胃炎吃什么药能治好| 有什么病| 纳呆是什么意思| 肺阳虚吃什么中成药| 兔死狐悲指什么生肖| 便秘吃什么药见效快| 打飞机是什么| 唯女子与小人难养也什么意思| 1939年属什么| 梦到女儿丢了什么预兆| 静心什么意思| 宫颈多发纳氏囊肿是什么意思| 双肺散在纤维灶是什么意思| 斑是什么原因造成的| 半夜鸡叫是什么征兆| 痔疮是什么样的| 威海是什么海| 十个一是什么| 井底之蛙的寓意是什么| 为什么门牙突然有缝了| 白芽奇兰是什么茶| 恨铁不成钢是什么意思| 伤心的反义词是什么| cartier什么牌子| 螃蟹不能和什么一起吃| 阑尾炎手术后可以吃什么| 放疗起什么作用| 乌龟死了有什么预兆| 吃辣椒过敏是什么症状| 痤疮是什么引起的| 八月六号是什么星座| 骨皮质断裂是什么意思| 蛋白高是什么原因| 维生素什么牌子好| 什么人容易得老年痴呆| 膝盖不舒服挂什么科| 发扬什么词语搭配| 熟普属于什么茶| 1958年属什么| 理数是什么意思| 睡觉后脑勺出汗多是什么原因| 汗毛长是什么原因| 肺部有结节要注意什么| gucci是什么意思| 庚五行属什么| 胃有灼热感是什么原因| 铁蛋白偏低是什么意思| 云南小黄姜和普通姜有什么区别| 脖子上长小肉疙瘩是什么原因| 苎麻是什么| 小肝功能是检查什么| 招商是什么工作| 樟脑是什么| 胰岛素是什么器官分泌的| 拜阿司匹灵是什么药| 接吻要注意什么| 百度Jump to content

青海禁毒公益宣传万里行走进贵德

From Wikipedia, the free encyclopedia
百度 火箭队首节就取得13分的领先,半场时比分甚至达到64:37。

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-07.
  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-07.
  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-07.
  5. ^ a b Boccara, Jonathan (2025-08-07). "The Most Vexing Parse: How to Spot It and Fix It Quickly". Fluent C++. Archived from the original on 2025-08-07. Retrieved 2025-08-07.
  6. ^ Stroustrup, Bjarne (19 August 2016). "C++11 FAQ". www.stroustrup.com. Uniform initialization syntax and semantics. Archived from the original on 2025-08-07. Retrieved 2025-08-07.
  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-07.
  8. ^ Devlieghere, Jonas (2025-08-07). "Guaranteed Copy Elision". Jonas Devlieghere. Archived from the original on 2025-08-07. Retrieved 2025-08-07. Note, however, the caveats covered in Brand, C++ (2025-08-07). "Guaranteed Copy Elision Does Not Elide Copies". Microsoft C++ Team Blog. Archived from the original on 2025-08-07. Retrieved 2025-08-07.
[edit]
黄瓜敷脸有什么效果 梦见自己手机丢了是什么意思 六味地黄丸什么功效 ctc什么意思 属猴的和什么属相最配
尖湿锐吃什么药最好 结婚六十年是什么婚 春天能干什么 血压低吃什么最快最有效 什么呀
贫血吃什么补 生日可以送什么礼物 风热感冒用什么药好 男性手心热是什么原因 上半身胖属于什么体质
甲亢可以吃什么水果 小鸟站在高压线上为什么不会触电 西洋参不能和什么一起吃 痔疮挂什么科室 辅酶q10的作用是什么
叫嚣是什么意思wuhaiwuya.com 尿蛋白阳性什么意思xinmaowt.com 夕阳什么意思hcv8jop0ns1r.cn 糜烂性胃炎有什么症状hcv8jop5ns1r.cn 趣味相投是什么意思hcv8jop4ns2r.cn
咳嗽有痰吃什么药好得最快最有效hcv9jop1ns0r.cn 不孕不育查什么项目hcv9jop3ns0r.cn 冰冻三尺的下一句是什么hcv8jop8ns8r.cn 什么可以治早泄hcv8jop7ns7r.cn 检查肾挂什么科hcv9jop0ns6r.cn
藏青和藏蓝有什么区别hcv9jop7ns4r.cn 男人耳后有痣代表什么hcv9jop0ns5r.cn 加白是什么意思hcv9jop4ns1r.cn 血脂稠吃什么hcv8jop8ns0r.cn 乌灵参是什么东西hcv8jop6ns3r.cn
加德纳菌阳性是什么意思fenrenren.com 田五行属什么hcv7jop5ns3r.cn 开业送什么hcv8jop1ns8r.cn 本科专科有什么区别hcv8jop8ns4r.cn 正科级是什么级别hcv7jop7ns3r.cn
百度