|
#include <iostream> int main() //为什么没有打印 operator= |
|
| 5分 |
哪个老师,哪本书告诉你
Test t1 = t; 是调用operator=的??! |
| 10分 |
class Test
{
public:
Test()
{
std::cout<<"构造 "<<std::endl;
}
Test(const Test & t)
{
std::cout << "拷贝构造" << std::endl;
}
~Test()
{
std::cout<<"析构 "<<std::endl;
}
const Test & operator = (const Test &t)
{
std::cout<<"operator= "<<std::endl;
return *this;
}
};
运行结果: |
| 5分 |
test t1=t 调用的是拷贝构造函数
|
|
原来如此,调用的是拷贝构造函数 |
|