作者在 2009-05-17 12:50:09 发布以下内容
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
class person
{string pname;
//char*pname;
public:
person(char* pn="noname")
{cout<<"constructing "<<pn<<endl;
//pname=new char[strlen(pn)+1];
//if( pname) strcpy(pname,pn);
pname=pn;
}
person(const person &s)
{cout<<"copy constructing "<<s.pname<<endl ;
//pname=new char[strlen(s.pname )+1];
//if(pname) strcpy(pname,s.pname );
}
~person()
{cout<<"destructing "<<pname<<endl;
}
#include<string>
#include<iomanip>
using namespace std;
class person
{string pname;
//char*pname;
public:
person(char* pn="noname")
{cout<<"constructing "<<pn<<endl;
//pname=new char[strlen(pn)+1];
//if( pname) strcpy(pname,pn);
pname=pn;
}
person(const person &s)
{cout<<"copy constructing "<<s.pname<<endl ;
//pname=new char[strlen(s.pname )+1];
//if(pname) strcpy(pname,s.pname );
}
~person()
{cout<<"destructing "<<pname<<endl;
}
};
void main()
{person p1("zhang");
person p3(p1);
}
运行结果有点小错 不知道那错 请指点下巴