• 对于定义一般类型的别名,二者没有区别。
  • 对于定义模板的别名,只能用using。(c++11 还是鼓励用using)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

template <typename T>
class A
{
public:
A() { std::cout << "A " << typeid(T).name() << std::endl; }
};

template <typename T>
using B = A<T>;

template <typename T>
typedef A<T> C;

int main()
{
A<int> a;
B<int> b; // OK, B is an alias of class A.
C<int> c; // Syntax Error, C cannot be recognized as a type.
return 0;
}