C++ 指向函数指针

刚做了个程序,需要通过调用结构体属性执行函数,百度了一下,豁然开朗。下面是相关代码:

指向无返回值函数:

#include <iostream>

typedef void(*voidPointer)();

struct testPointerStruct{
   voidPointer TestPointer; 
};

void hahah();

int main(){
    testPointerStruct testPointerObject;
    testPointerObject.TestPointer=hahah;
    testPointerObject.TestPointer();
}

void hahah(){
    std::cout << "测试" << std::endl;
}

输出结果:

猜你喜欢

转载自www.cnblogs.com/oinx/p/funcPointer1.html