拷贝构造 赋值构造

来源:互联网 发布:英雄联盟17173数据库 编辑:程序博客网 时间:2024/04/30 15:05
#include <iostream>
using namespace std;
class CA
{
public:
CA(int b, char *cstr)
{
a = b;
str = new char[b];
strcpy(str, cstr);
}
CA(const CA& Other)
{
a = Other.a;
str = new char[a];
if(str!=0)
strcpy(str,Other.str);
}
CA & operator = (CA & Other)
{
if(this == &Other)
return *this;
a = Other.a;
delete []str;
str = new char[a];
strcopy(str, cstr);
return this;
}
~CA()
{
delete str;
}
private:
int a;
char *str;
};

0 0
原创粉丝点击