How is this a most vexing parse?

夙愿已清 提交于 2019-12-30 20:52:53

问题


I was going through this article

and there is a statement in item 3 saying

// C++98 
rectangle       w( origin(), extents() );       // oops, vexing parse

how is the above a most vexing parse. If I did something like this

struct origin
{
};
struct Rectangle
{
    Rectangle(const origin& s)
    {
    }
};

The statement

 Rectangle s(origin());    

works fine and does not resemble a vexing parse. Why did the author say that its a vexing parse. Is that a typo or am I missing something ?


回答1:


Rectangle s(origin()); is a vexing parse too. It declares a function s which returns rectangle, and takes as argument pointer to function returning origin. Not sure what you meant by "works fine".

rectangle w( origin(), extents() ); declares a function w returning rectangle and taking arguments: pointer to function returning origin, and pointer to function returning extents.

For more detail see this question or browse the other questions under the most-vexing-parse tag.



来源:https://stackoverflow.com/questions/31574575/how-is-this-a-most-vexing-parse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!