-
大小: 2.80KB文件類型: .zip金幣: 1下載: 0 次發(fā)布日期: 2021-02-21
- 語言: C/C++
- 標簽:
資源簡介
C++實戰(zhàn)源碼-訪問類中私有成員的函數(shù)(入門級實例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)//構(gòu)造函數(shù)
{
strcpy(nameName);
age?=?Age;
}
friend?char?*?GetName(CPerson&p);//定義友員函數(shù)
};
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
評論
共有 條評論