【问题标题】:Error partial template specialization at compile GCC, but not MSVC编译 GCC 时出现部分模板专业化错误,但 MSVC 没有
【发布时间】:2011-12-22 18:00:42
【问题描述】:

以下代码,可以很好地编译 MSVC,但是在构建 GCC 时会出现很多错误:

#define FORCE_INLINE inline
#define CREF(A) const A&

template <class F>
class RDOFunCalcStd: public RDOFunCalc
{
...
template <class T>
FORCE_INLINE T getParam(CREF(LPRDORuntime) pRuntime, ruint paramNumber);

template <>
FORCE_INLINE double getParam<double>(CREF(LPRDORuntime) pRuntime, ruint paramNumber)
{
    return pRuntime->getFuncArgument(paramNumber).getDouble();
}

template <>
FORCE_INLINE int getParam<int>(CREF(LPRDORuntime) pRuntime, ruint paramNumber)
{
    return pRuntime->getFuncArgument(paramNumber).getInt();
}
...
};

错误列表:

错误:非命名空间范围‘class rdoRuntime::RDOFunCalcStd’中的显式特化

错误:主模板声明中的模板 ID 'getParam'

错误:非命名空间范围‘class rdoRuntime::RDOFunCalcStd’中的显式特化

错误:主模板声明中的模板 ID 'getParam'

错误:'int rdoRuntime::RDOFunCalcStd::getParam(const rdoRuntime::LPRDORuntime&,毁坏)' 不能重载

错误:带有'double rdoRuntime::RDOFunCalcStd::getParam(const rdoRuntime::LPRDORuntime&,毁坏)'

应该怎么做才能解决这个错误?

【问题讨论】:

    标签: c++ templates visual-c++ gcc syntax-error


    【解决方案1】:

    看到这个

    Article from Herb Sutter

    它解释了原因。简而言之,C++ 不支持函数模板特化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-11
      • 2018-06-22
      • 1970-01-01
      • 2011-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多