相关疑难解决方法(0)

C++语法/语义问题:引用Function和typedef关键字

typedef int (&rifii) (int, int)用什么?

这个"声明"之前的typedef是什么?我想把它想象成这样

typedef (int (&rifii) (int, int)) [new name]
Run Code Online (Sandbox Code Playgroud)

但如果你这样做的话,[新名字]并不存在

typedef int INTEGER;
Run Code Online (Sandbox Code Playgroud)

类似的问题,以下语法:

typedef void (*PF) ();

PF edit_ops[ ] = { &cut, &paste, &copy, &search };
PF file_ops[ ] = { &open, &append, & close, &write };

PF* button2 = edit_ops;
PF* button3 = file_ops;

button2[2]( );
Run Code Online (Sandbox Code Playgroud)

什么是typedef允许?它是否正在制作,因此您无需键入:

void (*PF) ();
(void (*PF) ()) edit_ops[ ] = { &cut, &paste, &copy, &search };
(void (*PF) ()) file_ops[ ] = { &open, &append, …
Run Code Online (Sandbox Code Playgroud)

c++ typedef function-pointers reference

7
推荐指数
1
解决办法
2086
查看次数

功能指针在C中使用typedef

如果我想typedef为某个类型声明一个,我会在这个例子中使用类似这样的语法:

typedef int INT
Run Code Online (Sandbox Code Playgroud)

但是当我想创建一个typedef函数时,我期待以下语法:

typedef void (*)(int, char) myfunc;
Run Code Online (Sandbox Code Playgroud)

相反,正确的是:

typedef void (*myfunc)(int, char);
Run Code Online (Sandbox Code Playgroud)

那么为什么第一个不正确呢?

c

1
推荐指数
1
解决办法
211
查看次数

标签 统计

c ×1

c++ ×1

function-pointers ×1

reference ×1

typedef ×1