Are there cases where a typedef is absolutely necessary?

后端 未结 8 1172
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 01:21

Consider the following excerpt from the safe bool idiom:

typedef void (Testable::*bool_type)() const;
operator bool_type() const;

Is it possibl

8条回答
  •  佛祖请我去吃肉
    2021-02-05 01:57

    I just ran across this issue, with clang++:

    foo.cpp:17:8: error: must use a typedef to declare a conversion to 'void (*(int))()'
    

    and there's a C++11 STL template which covers the identity functionality:

    #include 
    …
    struct foo {
         void bar( ) const { }
         operator std::common_type::type( ) { return &foo::bar; }
    };
    

提交回复
热议问题