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

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

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

2019-11-11 06:50:23
字體:
來源:轉載
供稿:網友

#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;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桐城市| 麻江县| 青龙| 黄骅市| 阜新| 色达县| 永新县| 泸西县| 横峰县| 台山市| 久治县| 萨嘎县| 湘西| 元谋县| 民县| 壶关县| 宿州市| 府谷县| 安多县| 仁化县| 鹰潭市| 咸宁市| 隆尧县| 景德镇市| 张家口市| 银川市| 海口市| 合作市| 赤水市| 鄱阳县| 三都| 岳阳市| 定边县| 高邮市| 柳林县| 许昌县| 雅江县| 金昌市| 双流县| 紫阳县| 洞口县|