Overloading the insertion operator
Posted on 2005-03-23
Hello, I have found something strange. I am using Visual C++ 6.0 SP6 so I am not sure if it is a bug with this or what but here goes.
I wrote a small piece of code:
const char *pMessage = "Hello World\n";
std::cout.operator<<(pMessage); // Prints out the address of pMessage
std::cout << pMessage; // Prints out the message
When I trace through the code the first call using cout matches the signature as const void * and the second one matches to basic_ostream<_E, _Tr>& _O, const _E *_X in this case: basic_ostream<char, char_traits<char>>& _O, const char *_X as far as I am aware.
What I don't understand is why operator<<() is using a different signature from plain << I thought they are synonymous. Can anyone tell me why? Is it a bug to do with Microsofts C++ compiler?