Reputation: 23
I used a template within a c++ class. However, when I try to call a function using a template from another function in the class, I get an error. What should I fix?
void MyClass::Display()
{
cout << "sum : ";
cout << setw(30) <<Add();
}
template <typename T>
T MyClass::Add()
{
T sum=0;
for (int i = 0; i < 15; i++)
{
sum += y[i];
}
return sum;
}
In this way, an error occurs in add() of the display part
Upvotes: 0
Views: 45
Reputation: 389
You want to use Add(). But you do not specify the template argument for Add()
you want to use.
You can specify it by: Add<*type*>()
Upvotes: 1