【问题标题】:Templated arguments [duplicate]模板化参数 [重复]
【发布时间】:2014-09-15 01:53:39
【问题描述】:

将模板参数作为参数的函数的正确语法是什么,即

 void myFunction (const Foo::Bar<T>& x)

是吗

 template<typename T>
 void myFunction (const typename Foo::Bar<T>& x)

另外,我应该使用

template<typename T>

或者

template<class T>

谢谢。

【问题讨论】:

标签: c++ templates


【解决方案1】:

你明白了。

template<typename T>
void myFunction (const typename Foo::Bar<T>& x)

是正确的。使用classtypename 都没有关系。 typename 是首选,class 是出于历史原因。不过,它们完全相同。查看this question 以获得一些解释。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-30
    • 1970-01-01
    • 1970-01-01
    • 2019-02-04
    • 1970-01-01
    • 2015-02-19
    • 2012-11-06
    • 2014-02-25
    相关资源
    最近更新 更多