析构函数的例子
#include<iostream>#include <string>
using namespace std;
class Student
{public:
student(int n,string nam,char s)
{num=n;
name=nam;
sex=s;
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(101,"Wangli",'f');
stud1.display();
Student stud2(102,"Limin",'m');
stud2.display();
return 0;
课本一道例题,运行不出来,