使用-声明现有名称空间类型与创建类型别名 [英] Using-declaration of an existing namespace type vs creating a type alias
本文介绍了使用-声明现有名称空间类型与创建类型别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这不是关于using
和typedef
在创建类型别名方面的区别的问题.我想提供从代码块或函数内部的命名空间访问现有类型的方法.
This is not a question about the difference between using
and typedef
for creating type aliases. I would like to provide access to an existing type from a namespace inside a code block or a function.
我发现了两种不同的方式:
I found two different ways :
我可以使用using声明包含"类型:
I can "include" the type with a using declaration :
using typename mynamespace::mytype;
或者我可以创建一个类型别名:
Or I can create a type alias :
typedef mynamespace::mytype mytype;
using mytype = mynamespace::mytype; //C++11
- 有什么区别吗?
- 每种语法的优缺点是什么?
- 哪个是最常用/推荐的?
谢谢.
查看全文