热门

最新

红包

立Flag

投票

同城

我的

发布
2301_76497243
2301_76497243
2 年前
true2301_76497243

#include <iostream>
#include <cstring>
using namespace std;
class Student
{
private:
char* name;
string id;
int score;
public:
Student(char*name1,string id1,int score1);
Student(const Student &p);
void print();
~Student();
};
Student::Student(char*name1,string id1,int score1):name(name1),id(id1),score(score1)
{
name = new char[strlen(name1) + 1];
strcpy(name, name1);
id=id1;
score=score1;
}
Student::Student(const Student &p)
{
name = new char[strlen(p.name) + 1];
strcpy(name, p.name);
id=p.id;
score=p.score;
}
Student::~Student()
{
delete[]name;
}
void Student::print()
{
cout<<name<<endl<<id<<endl<<score<<endl;
}
int main()
{
Student s1("limingcan","1",100);
s1.print();
Student s2=s1;
s2.print();
}

CSDN App 扫码分享
分享
评论
点赞
打赏
  • 复制链接
  • 举报
下一条:
CSDN打卡+2,开始元气满满的一天!生命不息,Coding不止。
立即登录