以下是语言新手的常见拼写错误,他们认为他们正在定义一个对象,但实际上是在声明一个函数:
struct T
{
void foo() {}
};
int main()
{
T obj();
obj.foo();
}
GCC 4.1.2 的错误是:
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.
为什么消息中报告的类型是T ()()
?我早就料到了T ()
。