0

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

1

1 Answer 1

1

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*>()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.