Overloading Friend Operator
When trying to overload the
In the provided code, the friend declaration for the
friend ostream& operator<<(ostream&, Pair<T,U>&);
However, the compiler recommends adding brackets to the function name, indicating that it should be declared as a template function. The correct syntax is:
friend ostream& operator<< <> (ostream&, Pair<T,U>&);
This declares the
Remember, the template function declaration should also be placed before the Pair class template definition to ensure that the compiler is aware of the template function when parsing the friend declaration. The corrected code with the correct friend declaration and template function declaration:
template <class T, class U> class Pair;
template <class T, class U>
ostream& operator<< <> (ostream&, Pair<T,U>&);
// Pair template class definition...
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3