Member_function_pointer_type () operator without typedef?

Is it possible to create an operator member_function_pointer_type() without using typedefs (i.e. specifying the type of the built-in pointer of a member function)?

For example, when implementing Idoom Safe Bool:

 class Foo { typedef void (Foo::*bool_type)() const; public: operator bool_type() const; }; 

Is it possible to write the bool_type type directly when declaring a statement? If so, how?

+5
c ++ syntax operator-overloading typedef member-function-pointers
source share
1 answer

This seems to be the only case where you cannot declare a (typecasting) operator without using a typedef .

If it was a different function name or another operator x , then it works fine:

 class Foo { typedef void (Foo::*bool_type)() const; public: operator bool_type() const; // other syntax void (Foo::* some_func () const) () const; // ok! named function void (Foo::* operator * () const) () const; // ok! operator * void (Foo::* operator () const) () const; // error! typecasting operator }; 

Demo

+1
source share

All Articles