/**
*cppTest-6.2:复制构造函数测试
*
*author 炜sama
*/
#include<iostream.h>
#include<string.h>
class string{
private:
char *str;
public:
string(char *s)
{
str=new char[strlen(s)+1];
strcpy(str,s);
}
//用对象初始化新对象时使用
//如果注释这个函数运行时会报错!
string(string &a)//&不能漏!去掉的话编译错误!
{
str=new char[strlen(a.str)+1];
strcpy(str,a.str);
//a.str="xxxxx";
}
~string(){ delete str; }
void show(){ cout<<str<<endl; }
};
void main()
{
string s1="Beijing";
string s2=s1;
s1.show();
s2.show();
}