Error: Request For Member '..' in '..' Which Is of Non-Class Type

error: request for member '..' in '..' which is of non-class type

Foo foo2();

change to

Foo foo2;

You get the error because compiler thinks of

Foo foo2()

as of function declaration with name 'foo2' and the return type 'Foo'.

But in that case If we change to Foo foo2 , the compiler might show the error " call of overloaded ‘Foo()’ is ambiguous".

C++ request for member ‘’ in ‘’, which is of non-class type ‘’

Rectangle s();

is a function declaration rather than variable. In c++ anything that can be parsed as a function declaration takes that parsing over the variable alternative. Removing the () would make it a variable.

error request for member which is of non class type Date (int,int,int)

The following line:

Date d (int Day, int Month, int Year);

Actually is a forward declaration of the function taking three integers as input and returning Date object.

Date d (Day, Month, Year); // proper construction

error: request for member '..' in '..' , which is of non-class type

This is a parsing issue. Let's break it apart:

CompareReachDist(&reach_dists)

You may think this creates a temporary CompareReachDist with the address of the static reach_dists. But in the context of the overall declaration it is interpreted as a reference to a CompareReachDist. Strange, but that is because, roughly speaking, the grammar of C++ favors function declarations to object declaration. The following

pq seeds(CompareReachDist(&reach_dists));

Is an overall declaration of a function. It accepts a CompareReachDist& and returns a pq.

The error you receive is because, quite obviously, a function doesn't have an empty member you can call.

The solution since C++11 is to favor list initialization, which breaks the ambiguity and its resolution as a function declaration. So you can do this:

pq seeds{CompareReachDist{&reach_dists}};

And get an object, as one would expect.



Related Topics



Leave a reply



Submit