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
When Should I Use Std::Thread::Detach
How to Compile a 64-Bit Application Using Visual C++ 2010 Express
Deoptimizing a Program For the Pipeline in Intel Sandybridge-Family Cpus
What Is the Meaning of the Term "Free Function" in C++
Generating Combinations in C++
C++ Code File Extension? Difference Between .Cc and .Cpp
Create Registry Entry to Associate File Extension With Application in C++
Use 'Class' or 'Typename' For Template Parameters
Why Can't Variable Names Start With Numbers
Boolean Expression (Grammar) Parser in C++
Why Aren't Pointers Initialized With Null by Default
Why Is Conversion from String Constant to 'Char*' Valid in C But Invalid in C++
What Do 1.#Inf00, -1.#Ind00 and -1.#Ind Mean