When I do the following:
template
class Container
{
public:
class Iterator
{
friend bool operator==(const Iterator& x,
It's warning about the fact that it is going to be virtually impossible to define that operator==
out-of-class.
That is to say, that friend
declaration befriends a non-template operator==
function - for example, Container
has as a friend the function
bool operator==(const Container::Iterator&, const Container::Iterator&);
This function is not a template, so there's pretty much no way to define operator==
for all possible Container
s outside the class template definition.
If you try to do
template
bool operator==(const Container::Iterator&, const Container::Iterator&);
That's a function template, and doesn't match the friend declaration. (In this case it's even worse, as you can't actually use this operator because T
is in a non-deduced context.)
The warning message suggests one possible fix - first declaring a function template and then befriending a specialization of it. (You'll need to pull Iterator
out of the class into its own separate class template so that T
can be deduced.) The other possible fix is to just define the function inside the class template definition.