首页 > 其他 > 详细

构造函数与析构函数(其中有两点值得学习)

时间:2016-05-24 06:53:19      阅读:176      评论:0      收藏:0      [点我收藏+]

// 构造函数与析构函数.cpp : 定义控制台应用程序的入口点。
//要学习的两点:
//要想表现出析构函数,必须在对象外面加大括号!!
//  while (cin.get() != ‘\n‘)   num++;
#include "stdafx.h"
#include<iostream>
using namespace std;
class Count
{
public:
    Count();
    ~Count();
    void process();
private:
    int num;
};

Count::Count()
{
    num = 0;
}

Count::~Count()
{
    cout << "The length of sentence:" << num << endl;

}

void Count::process()
{
    while (cin.get() != ‘\n‘) //this is need to study!!
        num++;
}
int main()
{
    {
        Count c;
        c.process();
    }//要想表现出析构函数,必须在对象外面加大括号!!
    system("pause");
    return 0;
}
技术分享

构造函数与析构函数(其中有两点值得学习)

原文:http://www.cnblogs.com/summercloud/p/5522122.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!