#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
using namespace std;
class base
{
public:
base()
{
cout << "*" << endl;
}
base(int n)
{
id_ = n;
}
base(const base& t)
{
id_ = t.id_;
cout << "***" <<endl;
}
base& operator=(const base& t)
{
id_ = t.id_;
cout << "**" << endl;
return *this;
}
private:
int id_;
};
int main(int argc, char* argv[])
{
base a(3);
base b = a;//赋值初始化调用的是拷贝构造函数
return 0;
}
输出:“***”
类的赋值初始化
最新推荐文章于 2023-02-13 10:33:20 发布