anio
anio

Reputation: 9161

typedef declaration syntax understanding?

I ran into this code and don't know what it does. Can you decipher it?

typedef std::map<std::string, bool (Foo::*)()> x_t;

The part I don't understand is the value of the map. I'm surprised its valid c++ syntax.

Thanks.

Upvotes: 3

Views: 86

Answers (2)

Adam H. Peterson
Adam H. Peterson

Reputation: 4591

x_t is a map from a string to a pointer-to-member-function-of-Foo returning bool.

You can read C++ declarations backwards, or in some cases, inside out. The value of the map is read from the * as a Foo member function returning bool, the key of the map is clearly a string, and x_t is a type alias for a map from key to value.

Upvotes: 1

Casey
Casey

Reputation: 42554

bool (Foo::*)() is a pointer to member function of Foo that takes no arguments and returns bool. So x_t is probably used to map names of member functions to the actual members.

Upvotes: 6

Related Questions