看下面代码
class Test{
};
class Test2{
public:
Test2(Test *t){}
};
int main(){
Test test();//把定义一个对象 “Test test;” 写成 “Test test();”函数声明了!
Test2 test2(&test);//
return 0;
}
Dev-cpp的提示信息:
no matching function for call to `Test2::Test2(Test (*)())'
VC的提示信息:
不能将参数 1 从“Test(__cdecl *)(void)”转换为“Test *” .
---
“Test(__cdecl *)(void)”是函数指针类型
“Test *”是对象的指针
所以在 重复的设计构造函数时候,要注意对象的定义格式,不要多写了“()”。