Reputation: 385295
The following is a common typo with language newcomers, who think that they are defining an object but are actually declaring a function:
struct T
{
void foo() {}
};
int main()
{
T obj();
obj.foo();
}
GCC 4.1.2's error is:
In function 'int main()':
Line 9: error: request for member 'foo' in 'obj', which is of non-class type 'T ()()'
compilation terminated due to -Wfatal-errors.
Why is the reported type in the message T ()()
? I'd have expected T ()
.
Upvotes: 2
Views: 187
Reputation: 180030
The error is best understood when you realize that you usually don't write out function types without naming at least the function, but it's a bit more common for function pointers.
For instance, int (*fooPtr)()
names the pointer. If you omit the name, you have int (*)()
. Now, going from function pointer to function type would give you int ()()
.
There's no real standard here, because ISO C++ doesn't define canonical names for all types. For instance, const volatile int
is the same type as volatile const int
, and neither form is canonical.
Upvotes: 2
Reputation: 17159
IIRC this is just a compiler bug. GCC 4.4 says T()
while 4.2 says T()()
for me.
Upvotes: 5