函数指针数组没有一个typedef [英] Array of Function Pointers Without a typedef

查看:169
本文介绍了函数指针数组没有一个typedef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

函数指针数组可以像这样创建:

 无效的typedef(* FunctionPointer)();
FunctionPointer FunctionPointers [] = {/ *的东西在这里* /};

什么是创建一个函数指针数组,而无需使用的typedef

语法
解决方案

  //编曲改编
ARR [] //是一个数组(这样编入索​​引)
* ARR []指针//(所以他们解引用)
(*常用3 [])()//采取什么功能(所以用打电话给他们())
无效(* ARR [])()//返回void

所以你的答案是

 无效(*常用3 [])()= {};

不过自然,这是一个不好的做法,只需要使用的typedef :)

额外的:
想知道如何申报的3个指针数组功能以int和返回指针4功能服用双并返回字符数组? (散热效果如何,是吧?))

  //编曲改编
ARR [3] //是3数组(索引它)
*常用3 [3] //指针
(*常用3 [3])(INT)//采取INT(叫)功能,
*(*常用3 [3])(int)的//返回指针(解引用它)
(*(*常用3 [3])(INT))[4] // 4的阵列
((*(* ARR [3])(INT))[4])(双)//功能服用双
CHAR((*(*常用3 [3])(INT))[4])(双)//返回字符

:))

Arrays of function pointers can be created like so:

typedef void(*FunctionPointer)();
FunctionPointer FunctionPointers[] = {/* Stuff here */};

What is the syntax for creating a function pointer array without using the typedef?

解决方案

arr    //arr 
arr [] //is an array (so index it)
* arr [] //of pointers (so dereference them)
(* arr [])() //to functions taking nothing (so call them with ())
void (* arr [])() //returning void 

so your answer is

void (* arr [])() = {};

But naturally, this is a bad practice, just use typedefs :)

Extra: Wonder how to declare an array of 3 pointers to functions taking int and returning a pointer to an array of 4 functions taking double and returning char? (how cool is that, huh? :))

arr //arr
arr [3] //is an array of 3 (index it)
* arr [3] // pointers
(* arr [3])(int) //to functions taking int (call it) and
*(* arr [3])(int) //returning a pointer (dereference it)
(*(* arr [3])(int))[4]  //to an array of 4
((*(* arr [3])(int))[4])(double) //functions taking double
char  ((*(* arr [3])(int))[4])(double) //returning char

:))

这篇关于函数指针数组没有一个typedef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆