标题:析构函数的例子
只看楼主
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6809
专家分:42393
注 册:2010-12-16
得分:0 
test

我行我乐
我的博客:
http://blog.yuccn. net
2013-10-16 17:29
苑天尤
Rank: 2
等 级:论坛游民
帖 子:17
专家分:16
注 册:2013-10-12
得分:0 
#include<iostream>
#include<string>
using std::string;
using std::cout;
using std::endl;
class Student
{

private:
int m_num;
string m_name;
char m_sex;
public:
Student(int num,string name,char sex):m_num(num),m_name(name),m_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;
}
};
int main()
 {
     Student stud1 (101, "Wangli", 'f');
     stud1.display ();
     Student stud2 (102, "Limin", 'm');
     stud2.display ();
     return  0;
 }

 
2013-10-17 19:19
序曲萧邦
Rank: 2
等 级:论坛游民
帖 子:45
专家分:41
注 册:2012-11-17
得分:0 
细节问题。看看编程软件下面的提示。双击可以看看那里出问题。函数后面不用分号void  display()
{cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl<<endl;}
private:
    int  num;
    string  name:
    char   sex;
}
还有int main()
{} 括号括回去

新手学c中。还望多多指教
2013-10-18 17:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-421949-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029108 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved