Last Modification: December 11, 1999

Why is VC not seeing my friend declaration?
  This is an obscure VC bug, which shows up only with the right
combination of statements.  For example, the following code fragment will
show the problem:


#include <iostream>
using namespace std;
class A
{
// etc
public:
friend ostream& operator<<(ostream&, const A&);
};

ostream& operator<<(ostream&, const A&)
{
    // you will not be able to access A's private data here.
}

The problem only occurs if you use a friend declaration on a function that has not previously been declared, and have include the entire std namespace. Changing either of those two conditions will cure the problem, e.g. either:

#include <iostream>
using namespace std;
ostream& operator<<(ostream&, const A&);
class A
{ 
    // etc
}
or
#include <iostream>
using std::ostream;
class A
{
    // etc
}
will work.
Finally, this bug has been corrected in the Visual Studio 6.0 Service Pack 3.

References  and Samples: