回复 楼主 明晚打老虎
#include<iostream>#include<string.h>
using namespace std;
class CClass
{
public:
CClass(char *cName="",int snum=0);
~CClass()
{
cout<<"析构班级:"<<pname<<endl;
delete pname;
}
CClass(CClass &p)
{
pname=new char[strlen(p.pname)+1];
if(pname!=0)
strcpy(pname,p.pname);
num=p.num;
cout<<"创建班级的拷贝:"<<pname<<endl;
}
void Print();
private:
char*pname;
int num;
}
CClass::CClass(char*cName,int snum)
{
int length=strlen[cName];
pname=new char[length+1];
if(pname!=0)
{
strcpy(pname,cName);
}
num=snum;
cout<<"创建班级:"<<pname<<endl;
}
void CClass::Print()
{
cout<<pname<<"班的班级人数:"<<num<<endl;
}
int main
{
CClass c1("三年一班",65);
CClass c2(c1);
c1.Print();
c2.Print();
return 0;
}