Reputation: 1256
I have a 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)
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) ^~~~~~~~~~~~~~~
/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);
why is this error occurred? and how to fix it
Upvotes: 1
Views: 101
Reputation: 310980
The order of the template arguments in the definition
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);
Upvotes: 2