首先,显示调用构造函数符合c++语法吗?
初始化时调用和非初始化时调用有什么区别?
我写了一个程序
class Test{
int x;
public:
Test(int v):x(v) {}
void print() { cout << x << endl; }
void operator = (Test a)
{
x = a.x;
cout << "=" << endl;
}
};
int main()
{
Test t = Test(99);
t.print();
t = Test(10);
t.print();
return 0;
}
运行结果是
99
=
10
但还是不是很明白为什么。求大神解答。谢谢