Can someone explain what's going on with the test program below ?
On Windows / Visual Studio .NET
os << x << endl; uses operator<< ( ostream & , const string & )
but
cout << x << endl; uses operator<< ( ostream & , const X & ) as I expect.
On Linux / g++, operator<< ( ostream & , const X & ) is used in both cases.
Is this a bug on Windows or is there something in the standard that I'm not
aware off ?
Test program:
#include <iostream>
#include <istream>
#include <string>
#include <sstream>
using namespace std;
class X
: public string
{ };
ostream& operator<< ( ostream& strm, const X& x )
{
strm << "Okidoki : '" << static_cast<string>( x ) << "'";
return strm;
}
int main( void )
{
X x;
ostringstream os;
os << x << endl;
cout << os.str( );
return 0;
}
Thanks.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]