C++语言基础 例程 析构函数

贺老师的教学链接  本课讲解


析构函数示例

#include<string>
#include<iostream>
using namespace std;
class Student
{
public:
    Student(int n,string nam,char s)
    {
        num=n;
        name=nam;
        sex=s;
        cout<<"执行构造函数:"<<name<<" come."<<endl;
    }
    ~Student( )
    {
        cout<<"执行析构函数:"<<"Bye bye, "<<name<<"."<<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;
}



上一篇:AjaxControlToolkit的CalendarExtender的本地化


下一篇:汉能CIGS薄膜转化率再次刷新世界记录