Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is this a most vexing parse?

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 ?

like image 657
James Franco Avatar asked Jul 22 '15 21:07

James Franco


1 Answers

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.

like image 138
M.M Avatar answered Oct 23 '22 18:10

M.M