I have a structure in which the operator template type. Want to make the correct announcement of this structure in header. Write the following code
header file
struct add_positive {
template<typename T>
T operator()(T value, const T& now);
};
.cpp file
template<typename T>
add_positive add_positive::operator()(T value, const T& now) {
if (now >= 0) {
return value + now;
}
return value;
}
But when compiling get the following error:
error: prototype for ‘add_positive add_positive::operator()(T, const T&)’ does not match any in class ‘add_positive’
add_positive add_positive::operator()(T value, const T& now) {
error: candidate is: template<class T> T add_positive::operator()(T, const T&)
T operator()(T value, const T& now);
Can't understand what I did wrong?