正在加载图片...
student: student (int i, char*c, int a, float s) ∥构造函数 I cout<<"Constructing. "<<endl; age =a, score =s name new char[strlen(c)+1 ∥申请堆空间 if(name =0) strcpy(name, c) student: student (student& s) ∥拷贝构造函数 i cout<< Copy Constructing. "<<endl ∥一般成员简单复制 age=sage score=s score name= new char[strlen(s name)+11 ∥,先申请堆空间 if(name I =O) strcpy(name, sname) ∥析构函数2 student::student(int i,char* c,int a,float s) //构造函数 { cout<<“Constructing…”<<endl; id =i; age =a; score =s; name = new char[strlen(c) +1]; //申请堆空间 if(name !=0) strcpy(name,c); } student::student(student& s) //拷贝构造函数 { cout<<“Copy Constructing…”<<endl; id=s.id; //一般成员简单复制 age=s.age; score=s.score; name = new char[strlen(s.name) +1]; //先申请堆空间 if(name !=0) strcpy(name,s.name); //析构函数 }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有