65,211
社区成员
发帖
与我相关
我的任务
分享
#include <string>
#include <iostream>
using namespace std;
class CStudent
{
public:
student(int n,string nam,char s)
{
num = n;
name = nam;
sex = s;
cout << "Constructor called." << endl;
}
~student() //调用析构函数
{
cout << "Constructor called." << endl;
}
void display()
{
cout << "num:" << num << endl;
cout << "name:" << name << endl;
cout << "sex:" << sex << endl;
}
private:
int num;
string name;
//char name[10];
char sex;
};
int main()
{
CStudent student1(100, "zhangzhijun", 'f');
student1.display();
return 0;
}