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

问题描述

根据MSDN,typedef语法是:

according to MSDN the typedef syntax is:

很容易:

typedef int MY_INT;

但是成员函数指针typedef如何符合这个规则?

But how the heck does the member-function-pointer typedefs comply to this rule?

typedef int (MyClass::*MyTypedef)( int);

100%confusion - 同义词( MyTypedef )是在中间吗?

100% confusion – the synonym (MyTypedef) is in the middle?

有人可以解释什么逻辑步骤是从非常容易理解的MSDN的语法格式到反向/随机/前/

Can someone please explain what the logical steps are to get from the very easy to understand syntax format of MSDN to the reverse/random/front/last/mixed syntax thing of aboves typedef?

*编辑感谢所有的快速答案(和美丽的我的帖子):)

*edit thanks for all the fast answers (and the beautification of my post) :)

推荐答案

它不在中间。只要忘记成员函数一段时间,看看函数指针是如何定义的:

Its not in the middle. Just forget member-function for a while, see how a function pointer is defined:

int (*FuncPtr)(int);

这是你如何typedef它:

And this is how you would typedef it:

typedef int (*FuncPtr)(int);

简单!唯一的区别是,在typedef FuncPtr 中成为类型,而在指针声明中, FuncPtr 是一个变量

Simple! The only difference is, in the typedef FuncPtr becomes a type, while in the pointer declaration, FuncPtr is a variable.

同样,

int (MyClass::*MyTypedef)( int); //MyTypedef is a variable

typedef如下:

And the typedef as:

typedef int (MyClass::*MyTypedef)( int); //MyTypedef is a type!

这篇关于带有成员函数指针的typedef语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 21:23