[英]template function doesn't recognize
I have a class我有一个 class
template <class T>
class BaseStrategy
{
template<typename Period, typename Rep>
void print_time(tm t, chrono::duration<Rep, Period> fraction);
}
and the implemention is (in the same.h file)并且实现是(在同一个.h文件中)
template <typename T>
template <typename Rep, typename Period >
void BaseStrategy<T>::print_time(tm t, std::chrono::duration<Rep, Period> fraction)
{
/some code/
}
but when I compile the code I'm getting the following error:但是当我编译代码时出现以下错误:
error: prototype for 'void BaseStrategy::print_time(tm, std::chrono::duration<_Rep, _Period>)' does not match any in class 'BaseStrategy' void BaseStrategy::print_time(tm t, std::chrono::duration fraction) ^~~~~~~~~~~~~~~
错误:'void BaseStrategy::print_time(tm, std::chrono::duration<_Rep, _Period>)' 的原型与 class 'BaseStrategy' 中的任何内容都不匹配 void BaseStrategy::print_time(tm t, std::chrono: :duration 分数) ^~~~~~~~~~~~~~~
/home/yaodav/Desktop/git_repo/test/include/BaseStrategy.h:216:10: error: candidate is: template template void BaseStrategy::print_time(tm, std::chrono::duration) void print_time(tm t, chrono::duration fraction);
/home/yaodav/Desktop/git_repo/test/include/BaseStrategy.h:216:10: 错误:候选是:模板模板 void BaseStrategy::print_time(tm, std::chrono::duration) void print_time(tm t, chrono::duration 分数);
why is this error occurred?为什么会发生这个错误? and how to fix it
以及如何解决它
The order of the template arguments in the definition定义中模板 arguments 的顺序
template <typename Rep, typename Period >
void BaseStrategy<T>::print_time(tm t, std::chrono::duration<Rep, Period> fraction)
does not correspond to the order of the template parameters in the declaration与声明中模板参数的顺序不对应
template<typename Period, typename Rep>
void print_time(tm t, chrono::duration<Rep, Period> fraction);
Either write要么写
template<typename Rep, typename Period>
void print_time(tm t, chrono::duration<Rep, Period> fraction);
or (more confusing)或(更令人困惑)
template<typename Period, typename Rep>
void print_time(tm t, chrono::duration<Period, Rep> fraction);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.