0
我有一个构造函数和赋值运算符的问题。这是我的代码:c + +的构造函数和运算符问题
class Class
{
private:
double number1;
double number2;
public:
Class(double, double);
Class& operator=(const Class& n);
}
Class::Class(double n1 = 0.0, double n2 = 0.0)
{
this->number1 = n1;
this->number2 = n2;
}
Class& operator=(const Class& n)
{
this->number1 = n.number1;
this->number2 = n.number2;
return *this;
}
int main()
{
Class n1(2., 3.), n2(7., -1.), n3();
n2 = n1; // no problem
n3 = n1; // problem
return 0;
}
您能否让我欣喜若狂,为什么在第二个任务中出现问题?
非常感谢您
编辑:发生以下错误:
[Error] assignment of function 'Complex cislo2()'
[Error] cannot convert 'Complex' to 'Complex()' in assignment
您遇到什么样的问题?编译错误?运行时错误?你能否在你的问题中包含错误? – MetaFight
我将错误添加到原始帖子 – Adam
可能的重复[A a()是什么意思?](http://stackoverflow.com/questions/17713124/what-does-aa-mean) – amon