国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

全局函數指針數組typedef和成員函數指針數組類內外部typedef

2019-11-11 06:08:52
字體:
來源:轉載
供稿:網友

#include <iostream>#include <vector>// 1.對全局函數指針數組typedeftypedef void(*FuncType01)();typedef FuncType01 Func01Array[2];void foo() {	std::cout << "void foo()" << std::endl;}void bar(){	std::cout << "void bar()" << std::endl;}class A {public:	// 2.在類中對成員函數指針數組typedef	typedef void (A::*FuncType02)() const;	typedef FuncType02 Func02Array[2];	void foo() const { std::cout << "void foo() const" << std::endl; }	void bar() const { std::cout << "void bar() const" << std::endl; }	void test() const	{		// 調用2的,類內部類型前不需要加類的域		FuncType02 f = &A::foo;// 取成員函數地址必須加&,無論是否在類的內部還是外部		Func02Array fs = {&A::foo, &A::bar};		(this->*f)();		for (int i = 0; i < 2; i++)		{			(this->*fs[i])();		}	}};// 3.在類外對成員函數指針數組typedeftypedef void (A::*FuncType03)() const;typedef FuncType03 Func03Array[2];int main(){	// 調用1的	FuncType01 f1 = ::foo;//&可以不加	Func01Array fs1 = { &foo, &bar };	(*f1)();	for (int i = 0; i < 2; i++)	{		(*fs1[i])();	}	// 調用2的	A::FuncType02 f2 = &A::foo;// 取成員函數地址必須加&	A::Func02Array fs2 = {&A::foo, &A::bar};	A a;	(a.*f2)();	for (int i = 0; i < 2; i++)	{			(a.*fs2[i])();	}	// 調用3的,不需要加類的域	FuncType03 f3 = &A::foo;	Func03Array fs3 = {&A::foo, &A::bar};	A a2;	(a2.*f3)();	for (int i = 0; i < 2; i++)	{			(a2.*fs3[i])();	}	a.test();	return 0;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永新县| 克拉玛依市| 诸暨市| 云梦县| 岳池县| 健康| 滕州市| 随州市| 镶黄旗| 旬邑县| 义马市| 溆浦县| 神农架林区| 浠水县| 临猗县| 闸北区| 彰武县| 高清| 临湘市| 杭州市| 大理市| 南京市| 甘肃省| 集安市| 东宁县| 南充市| 佛教| 睢宁县| 社会| 西和县| 藁城市| 饶阳县| 镶黄旗| 墨竹工卡县| 乌兰浩特市| 察雅县| 句容市| 随州市| 婺源县| 婺源县| 木兰县|