本文介绍了C ++'typedef'vs.'using ... = ...'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码编译并运行。我的问题是typedef和使用方法之间的区别是什么重命名模板专业化?

The following code compiles and runs. My question is what is the difference between the "typedef" and "using" method for renaming the template specialization?

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;
}



编辑:



如果没有区别,你会喜欢哪一个? /为什么使用... = ...版本介绍?

If there is no difference, which one would you prefer? / Why was the using ... = ... version introduced?

推荐答案

strong>

They are the same.

引用C ++ 11标准(或草稿具体):

To quote the C++11 standard (or the draft to be specific):

我认为和typedef说明符相同的语义这样说。

这篇关于C ++'typedef'vs.'using ... = ...'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 15:38
查看更多