C++

学生类的析构和构造

#include <iostream>
#include <string.h>

using namespace std;

class Student
{
public:
Student(int _num,string _name,char _sex)
{
num=_num;
name=_name;
sex=_sex;
cout<<"Constructor called."<<endl;
}
~Student()
{
cout<<"Destructor called."<<endl;
}
void display()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl<<endl;
}
private:
int num;
string name;
char sex;
};

int main()
{

Student stud1(10010,"Wang_li",'f');
stud1.display();
Student stud2(10011,"Zhang_fun",'m');
stud2.display();
return 0;
}

posted @ 2023-05-25 21:31  涨涨涨张  阅读(5)  评论(0编辑  收藏  举报