Calling a specialized template function, when there is also a non-template function in C++

Viewed 696

In this example, how is it possible to call the second function?

template<class T>
T square(T a) {
    std::cout << "using generic version to square " << a << std::endl;
    return a*a;
}

/// "int" is so special -- provide a specialized function template
template<>
int square(int a) {
    std::cout << "using specialized generic version to square " << a << std::endl;
    return a*a;
}

/// and there's one more: a non-template square function for int
int square(int a) {
    std::cout << "using explicit version to square " << a << std::endl;
    return a*a;
}

Thanks in advance!

1 Answers
Related