What is the difference between 'typedef' and 'using' in C++11?

后端 未结 7 959
误落风尘
误落风尘 2020-11-22 03:32

I know that in C++11 we can now use using to write type alias, like typedefs:

typedef int MyInt;

Is, from what I

7条回答
  •  半阙折子戏
    2020-11-22 03:56

    They are essentially the same but using provides alias templates which is quite useful. One good example I could find is as follows:

    namespace std {
     template using add_const_t = typename add_const::type;
    }
    

    So, we can use std::add_const_t instead of typename std::add_const::type

提交回复
热议问题