資源簡介
C++實戰源碼-訪問類中私有成員的函數(入門級實例216).zip
代碼片段和文件信息
//?Friend.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?“ioStream.h“
#include?“string.h“
typedef?char?String[30];
class?CPerson
{
private:
String?name;//姓名
int?age;//年齡
public:
CPerson(String?Nameint?Age)//構造函數
{
strcpy(nameName);
age?=?Age;
}
friend?char?*?GetName(CPerson&p);//定義友員函數
};
char?*?GetName(CPerson&p)//獲取CPerson類私有信息
{
return?p.name;
}
int?main(int?argc?char*?argv[])
{
CPerson?p(“張三“25);
cout?< return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????573??2010-10-14?14:51??Friend\Friend.cpp
?????文件????????4536??2010-10-14?14:21??Friend\Friend.dsp
?????文件?????????537??2010-10-14?14:21??Friend\Friend.dsw
?????文件?????????293??2010-10-14?14:21??Friend\StdAfx.cpp
?????文件?????????769??2010-10-14?14:21??Friend\StdAfx.h
- 上一篇:C++實戰源碼-簡單的位運算
- 下一篇:C++實戰源碼-實現兩個變量的互換
評論
共有 條評論