Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typedef declaration syntax understanding?

Tags:

c++

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.

like image 568
anio Avatar asked Sep 14 '26 06:09

anio


2 Answers

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.

like image 118
Casey Avatar answered Sep 16 '26 18:09

Casey


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.

like image 26
Adam H. Peterson Avatar answered Sep 16 '26 18:09

Adam H. Peterson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!