开发者

Can somebody explain this C++ typedef?

I've just started working with C++ after not having worked with it for quite a while. While most of it makes sense, there are some bits that I'm finding a bit confuddling. For example, co开发者_如何学Gould somebody please explain what this line does:

typedef bool (OptionManager::* OptionHandler)(const ABString& value);


It defines the type OptionHandler to be a pointer to a member function of the class OptionManager, and where this member function takes a parameter of type const ABString& and returns bool.


typedef bool (OptionManager::* OptionHandler)(const ABString& value);

Let's start with:

OptionManager::* OptionHandler

This says that ::* OptionHandler is a member function of the class OptionManager. The * in front of OptionHandler says it's a pointer; this means OptionHandler is a pointer to a member function of a class OptionManager.

(const ABString& value) says that the member function will take a value of type ABString into a const reference.

bool says that the member function will return a boolean type.

typedef says that using "* OptionHandler" you can create many function pointers which can store that address of that function. For example:

OptionHandler fp[3];

fp[0], fp[1], fp[2] will store the addresses of functions whose semantics match with the above explanation.


this is a pointer to a member function of OptionManager that takes a const ABString refrence and returns a bool


It is a typedef to a pointer to member function. Please check C++ FAQ.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜