【发布时间】:2012-06-28 18:35:21
【问题描述】:
可能重复:
What are the differences between typedef and using in C++11?
以下代码编译并运行。我的问题是重命名模板专业化的“typedef”和“using”方法有什么区别?
template<typename T>
struct myTempl{
T val;
};
int main (int, char const *[])
{
using templ_i = myTempl<int>;
templ_i i;
i.val=4;
typedef myTempl<float> templ_f;
templ_f f;
f.val=5.3;
return 0;
}
编辑:
如果没有区别,你更喜欢哪一个? / 为什么要引入 using ... = ... 版本?
【问题讨论】:
-
不是模板的
using并不是真正的用例。 -
@Andrew 你说得对,我就是找不到那个。
-
@Simon:谷歌的第一个链接:google.com/…
-
你有没有注意到 C++11 到处都是从左到右的声明风格?使用
using写类型别名更符合新的C++11风格。这句话来自 Herb Sutter herbsutter.com/2013/08/12/…
标签: c++ c++11 typedef using-directives