資源簡介
C++實戰源碼-const函數的使用(入門級實例221).zip
代碼片段和文件信息
//?constFunction.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include
using?namespace?std;
class?Man //聲明一個Man類
{
private:
int?m_height;
int?m_weight;
public:
Man(int?hint?w);
void?display()const; //聲明一個常成員函數
};
Man::Man(int?h?int?w)
{
m_height=h;
m_weight=w;
}
void?Man::display()const //定義常成員函數,在其中引用成員變量
{
cout<<“the?height?of?man?is?:“< cout<<“the?weight?of?man?is?:“< }
int?main()
{
Man?man(170120); //定義一個Man類的對象
man.display(); //通過這個對象調用常成員函數
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????673??2010-10-14?17:59??constFunction\constFunction.cpp
?????文件????????4620??2010-10-14?17:59??constFunction\constFunction.dsp
?????文件?????????551??2010-10-14?17:59??constFunction\constFunction.dsw
?????文件?????????300??2010-10-14?17:59??constFunction\StdAfx.cpp
?????文件?????????769??2010-10-14?17:59??constFunction\StdAfx.h
評論
共有 條評論