Re: friends and operators
It's a bug. Declaring a friend function immediately below a 'using namespace std;' directive causes this problem (there is a bug report for it on the Microsoft web site).
The best workaround is not to use the 'using namespace std;' directive. This should really not be used in header files because it opens the whole std namespace for all subsequently included headers, which kind of defeats the object of namespaces. In headers, always use the explicit namespace prefix for names. It is best avoided in source files too. In source files, put a using declaration at the top of the file (below the headers) for each name used:
Header (.h) files:
#include <string>
// using namespace std; // Don't use
class Test
{
friend bool operator==( const Test& lhs, const Test& rhs );
private:
std::string s; // use explicit namespace prefix
};
bool operator==( const Test& lhs, const Test& rhs )
{ return ( lhs.s == rhs.s ); }
Source (.cpp) files:
#include <string>
// using namespace std; // don't use.
using std::string; // prefer using declaration for each name
class Test
{
friend bool operator==( const Test& lhs, const Test& rhs );
private:
string s;
};
bool operator==( const Test& lhs, const Test& rhs )
{ return ( lhs.s == rhs.s ); }
Hope this helps,
Dave Lorde