我收到以下代码的编译错误,但如果我删除复制构造函数语句,也会编译相同的错误。
谁能让我知道这种行为?
class MyClass
{
private:
int i;
MyClass(MyClass &);
public:
MyClass():i(0){}
};
int main(){
MyClass obj = MyClass();
return 0;
}
错误是:
MyClass.cpp: In function ‘int main()’: MyClass.cpp:15:24: error: no matching function for call to ‘MyClass::MyClass(MyClass)’ MyClass.cpp:15:24: note: candidates are: MyClass.cpp:11:2: note: MyClass::MyClass(MyClass&) MyClass.cpp:11:2: note: no known conversion for argument 1 from ‘MyClass’ to ‘MyClass&’ MyClass.cpp:10:2: note: MyClass::MyClass() MyClass.cpp:10:2: note: candidate expects 0 arguments, 1 provided