Skip to content

Chapter 2 page 22: Second example of a most vexing parse #4

@algor

Description

@algor

The continuation of a paragraph started on the previous page (21) descries the following line of code:

Product p2(Box());

as following:

Similarly, the line with p2 also causes errors.
This time the compiler thinks we declare a local function p2 returning a Product and taking
Box as an argument (Box() is treated as Box(*)(), which is a function declaration called
Box that takes no arguments and returns void).

I think the error here is that you correctly describe how the Box() is treated as Box(*)() but
then incorrectly interpret it in writing as "...which is a function declaration called Box that takes
no arguments and returns void."

Box(*)() is not a function called Box with no arguments and returning void.
It is an unnamed parameter with the type of a pointer to a function which does not take parameters
and which returns an object of type Box.

Please see item 2 of section "Unnamed temporary" at https://en.wikipedia.org/wiki/Most_vexing_parse

The error in this case will be "'Box' was not declared in this scope" which means the compiler is looking
for a type definition for the Box as a return type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions