解释隐式转换赋值构造和复制构造等一些列问题(运行就明白了)

来源:互联网 发布:阿里云黑洞触发值 编辑:程序博客网 时间:2024/06/06 12:27
#include <iostream>
#include <string>

using namespace std;

class A
{
public:
A();//default
A(A &);//copy
A & operator= (const A &);//equal
explicit A(string str);//string
};


A::A(string str)
{
cout << "string" << endl;
}


A::A()
{
cout << "default" << endl;
}


A & A :: operator= (const A &other)
{
cout << "=" << endl;
return *this;
}


A::A(A &a)
{
cout << "copy" << endl;
}


int main()
{
A a;
A b(a);
A c = a;
A d;
d = a;
A v = A("fsdfa");


return 0;
}