Are there cases where a typedef is absolutely necessary?

后端 未结 8 1154
爱一瞬间的悲伤
爱一瞬间的悲伤 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 02:02

    Answering the "Are there cases where a typedef is absolutely necessary?" from the question title, here is one example of where a typedef is needed:

    f(unsigned char());   // compiler error!
    typedef unsigned char Byte;
    f(Byte());            // fine!
    

    See the results here: http://ideone.com/JPUra

提交回复
热议问题