I have actually a course with two constructors, one the takes no arguments and also one the takes one argument.

You are watching: Request for member which is of non-class type

Creating objects utilizing the constructor the takes one argument works as expected. However, if I produce objects using the constructor the takes no arguments, I acquire an error.

For instance, if ns compile this password (using g++ 4.0.1)...

class Foo public: Foo() ; Foo(int a) ; void bar() ;;int main() // this works... Foo foo1(1); foo1.bar(); // this go not... Foo foo2(); foo2.bar(); return 0;... I gain the adhering to error:

nonclass.cpp: In function ‘int main(int, const char**)’:nonclass.cpp:17: error: inquiry for member ‘bar’ in ‘foo2’, i m sorry is of non-class form ‘Foo ()()’Why is this, and how carry out I make it work?


*

*

Foo foo2();change to

Foo foo2;You obtain the error due to the fact that compiler think of

Foo foo2()as of role declaration through name "foo2" and the return kind "Foo".

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


*

*

Just because that the record..

It is actually no a systems to your code, yet I had the exact same error message when incorrectly accessing the method of a class instance pointed to by myPointerToClass, e.g.

MyClass* myPointerToClass = brand-new MyClass();myPointerToClass.aMethodOfThatClass();where

myPointerToClass->aMethodOfThatClass();would obviously it is in correct.


*

Parenthesis is not compelled to instantiate a course object when you don"t intended to use a parameterised constructor.

Just use Foo foo2;

It will work.


Adding to the understanding base, I acquired the very same error for

if(class_iter->num == *int_iter)Even despite the principle gave me the exactly members for class_iter. Obviously, the trouble is the "anything"::iterator doesn"t have a member called num for this reason I have to dereference it. I m sorry doesn"t work like this:

if(*class_iter->num == *int_iter)...apparently. I ultimately solved it v this:

if((*class_iter)->num == *int_iter)I expect this help someone who runs throughout this inquiry the means I did.


I was having a similar error, it appears that the compiler misunderstand the contact to the constructor without arguments. Ns made it occupational by removing the parenthesis from the change declaration, in your password something like this:

class Foo public: Foo() ; Foo(int a) ; void bar() ;;int main() // this works... Foo foo1(1); foo1.bar(); // this go not... Foo foo2; // without "()" foo2.bar(); return 0;
I ran into a situation where I got that error message and also had

Foo foo(Bar());and was basically trying to pass in a short-term Bar thing to the Foo constructor. Turns out the compiler to be translating this to

Foo foo(Bar(*)());that is, a function declaration whose surname is foo that returns a Foo that takes in an debate -- a duty pointer returning a Bar through 0 arguments. As soon as passing in temporaries favor this, much better to use Bar instead of Bar() to eliminate ambiguity.


If you desire to explain a brand-new substance v no parameter (knowing the the object have default parameters) don"t write

form substance1();but

kind substance;
Certainly a corner situation for this error, yet I received it in a different situation, as soon as attempting to overload the assignment operator=. It to be a little cryptic IMO (from g++ 8.1.1).

See more: Why Do I Get " Array Indices Must Be Positive Integers Or Logical Values ”

#include enum DataType DT_INT32, DT_FLOAT;struct PrimitiveData union MyData int32_t i; to rise f; data; enum DataType dt; layout void operator=(T data) switch(dt) case DT_INT32: data.i = data; break; instance DT_FLOAT: data.f = data; break; default: break; ;int main() struct PrimitiveData pd; pd.dt = DT_FLOAT; pd = 3.4f; return 0;I received 2 "identical" errors

error: inquiry for member ‘i’ in ‘data’, i beg your pardon is of non-class form ‘float’(The indistinguishable error for clang is:error: member recommendation base type "float" is not a framework or union)

for the lines data.i = data; and data.f = data;. Turns out the compiler was confusing local variable name "data" and my member variable data. Once I changed this to void operator=(T newData) and also data.i = newData;, data.f = newData;, the error walk away.