Search code examples
c++c++11typestypedefusing

What's the difference between using-style and typedef-style?


using IntegerType1 = int;
typedef int IntegerType2;

int main()
{
    IntegerType1 n1 = 1; // OK
    IntegerType2 n2 = 2; // OK
}

My questions are:

  1. What's the difference between using-style and typedef-style?

  2. As we already have typedef-style, what's the motivation to make using-style become a C++ standard?


Solution

  • The "using-style" was introduced to allow templated typedefs:

    template< typename T >
    using int_map = std::map< int, T >;
    

    You can not do this with typedef. I found it strange myself that it was decided to use using and not typedef as the keyword for this, but I guess the committee must have found some problem with extending the typedef syntax.