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

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

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

2019-11-11 07:21:02
字體:
來源:轉載
供稿:網友

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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 盱眙县| 乐清市| 桐城市| 泗阳县| 邢台县| 潜山县| 南部县| 称多县| 绥化市| 曲阜市| 宜良县| 仲巴县| 四子王旗| 安顺市| 改则县| 奉化市| 巴塘县| 梨树县| 塘沽区| 苍溪县| 巍山| 常熟市| 茂名市| 平度市| 乃东县| 新疆| 冷水江市| 峡江县| 田东县| 来宾市| 奉化市| 陇西县| 察哈| 林周县| 青神县| 北海市| 都兰县| 宜良县| 栖霞市| 青神县| 乌兰浩特市|