This question already has an answer here:
I have the following three class definitions:
class String
{
public:
String() {}
String(const char *) {}
};
class ClassA
{
public:
ClassA(const String &) {}
};
class ClassB
{
public:
ClassB(const ClassA &, const String & = String()) {}
void method() {}
};
Now suppose I want to create an instance of ClassB
:
String name("test");
ClassA item(ClassB(name));
This doesn't work:
error: request for member 'method' in 'item', which is of non-class type 'ClassA ()(ClassB)'
What does this error mean? And what is this strange type ClassA ()(ClassB)
the compiler keeps referring to?
This is called most vexing parse problem.
should either be:
or:
Also have a look at: Most vexing parse: why doesn't A a(()); work?