what is the difference between the following two snippets?
<T>
for operator <<template<typename T>
class Stack {
...
friend std::ostream& operator<< <T> (std::ostream&,
Stack<T> const&);
};
<T>
template<typename T>
class Stack {
...
friend std::ostream& operator<< (std::ostream&,
Stack<T> const&);
};
In #1, the compiler will look for a function template called operator<<
such that operator<< <T>
has the precise signature given, and the class Stack<T>
will befriend only that particular specialization.
In #2, the compiler will look for a non-template function called operator<<
which has the precise signature given. If such a function is found, Stack<T>
will befriend it. If such a function is not found, the function is thereby declared (but this is a problematic situation since there's no way to generically define it).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With