码迷,mamicode.com
首页 > 编程语言 > 详细

C++ 指向函数指针

时间:2018-09-22 14:50:26      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:info   bubuko   属性   结果   div   com   输出   inf   结构体   

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

指向无返回值函数:

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

输出结果:

技术分享图片

C++ 指向函数指针

标签:info   bubuko   属性   结果   div   com   输出   inf   结构体   

原文地址:https://www.cnblogs.com/oinx/p/funcPointer1.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!