这里是我的代码构造对象和调用成员函数
#include <iostream>
using namespace std;
class MyTestClass
{
int MyTestIVar;
public:
MyTestClass(void);
int firstCallMethod(void);
int secondCallMethod(void);
};
MyTestClass::MyTestClass(void)
{
MyTestIVar = 4;
}
int MyTestClass::firstCallMethod(void)
{
return secondCallMethod();
}
int MyTestClass::secondCallMethod(void)
{
return MyTestIVar;
}
int main(int argc, char *argv[])
{
MyTestClass mTC;
cout << mTC.firstCallMethod() << endl;
return 0;
}
如果使用使用
MyTestClass mTC();
而是将不允许我打电话给任何成员函数,并显示此错误
./experiment.cpp: In function ‘int main(int, char**)’: ./experiment.cpp:31:14: error: request for member ‘firstCallMethod’ in ‘mTC’, which is of non-class type ‘MyTestClass()’
我读了关于value-initialize等的帖子,但是这个错误对我来说依然不合逻辑。为什么会影响会员功能?
和帮助非常感谢:-)
你确定这个代码示例是否足以重现错误?你是否也意味着如果你将行“MyTestClass mTC;”与“MyTestClass mTC();”只有那么错误发生? – 2012-01-17 10:06:02