模板功能无法识别

姚大夫

我有一堂课

template <class T>
class BaseStrategy
{
template<typename Period, typename Rep>
void print_time(tm t, chrono::duration<Rep, Period> fraction);
}

和实现是(在同一.h文件中)

template <typename T>
template <typename Rep, typename Period >
void BaseStrategy<T>::print_time(tm t, std::chrono::duration<Rep, Period> fraction)
{
    /some code/
}

但是当我编译代码时,出现以下错误:

错误:“ void BaseStrategy :: print_time(tm,std :: chrono :: duration <_Rep,_Period>)”的原型与类“ BaseStrategy”中的任何内容都不匹配void BaseStrategy :: print_time(tm,std :: chrono: :持续时间分数)^ ~~~~~~~~~~~~~~~

/home/yaodav/Desktop/git_repo/test/include/BaseStrategy.h:216:10:错误:候选者是:模板模板void BaseStrategy :: print_time(tm,std :: chrono :: duration)void print_time(tm, chrono :: duration fraction);

为什么会发生此错误?以及如何解决

来自莫斯科的弗拉德

模板参数在定义中的顺序

template <typename Rep, typename Period >
void BaseStrategy<T>::print_time(tm t, std::chrono::duration<Rep, Period> fraction)

与声明中模板参数的顺序不对应

template<typename Period, typename Rep>
void print_time(tm t, chrono::duration<Rep, Period> fraction);

要么写

template<typename Rep, typename Period>
void print_time(tm t, chrono::duration<Rep, Period> fraction);

或(更令人困惑)

template<typename Period, typename Rep>
void print_time(tm t, chrono::duration<Period, Rep> fraction);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章