【发布时间】:2020-02-15 06:52:50
【问题描述】:
这不是关于using 和typedef 创建类型别名的区别的问题。我想从代码块或函数中的命名空间提供对现有类型的访问。
我发现了两种不同的方法:
我可以使用 using 声明“包含”该类型:
using typename mynamespace::mytype;
或者我可以创建一个类型别名:
typedef mynamespace::mytype mytype;
using mytype = mynamespace::mytype; //C++11
- 有什么区别吗?
- 每种语法的优缺点是什么?
- 哪个是最常用/推荐的?
谢谢。
相关问题:Using-declaration of an existing type from base class vs creating a type alias inside child class
【问题讨论】:
标签: c++ typedef type-alias using-declaration