c++中类中有类student,可以student stu1,stu2;stu1=stu2吗?

c++中类中有类student,可以student stu1,stu2;stu1=stu2吗?
2024-11-24 02:05:00
推荐回答(1个)
回答1:

#include
using namespace std;

class Student //类使用class
{
public:
int num;
char name[20];
int age;
}stu1 = {1, "lin", 14}, stu2 = {2, "wang", 12};

int main()
{
Student *stu3 = new Student(); //使用new
*stu3 = stu1;
stu1 = stu2;
stu2 = *stu3;
delete(stu3); //使用delete

cout<<"Stu1:"<<" "<<"姓名:"<num<<" "<<"年龄:"< cout<<"Stu2:"<<" "<<"姓名:"<num<<" "<<"年龄:"< return 0;
}