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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With