* Alf P. Steinbach:
* Angel Tsankov:
Hello! Why does the second statement in main print a memory address
(tested with VC 2003 & 2005)?
#include <iostream>
wchar_t const* f()
{
static wchar_t const Str[] = L"aaa";
return Str;
}
class Proba
{
public:
operator wchar_t const*()
{
static wchar_t const Str[] = L"aaa";
return Str;
}
};
int main()
{
std::wcout <<f(); // Prints "aaa"
std::wcout <<Proba(); // Prints some memory address
}
It's very sad that [comp.std.c++] is (or seems to be) defunct, because
this question seems to belong there.
I suggest you post it to [comp.lang.c++.moderated], because as far as I
can see -- but relying on several months old draft -- it hasn't been
fixed in C++0x.
In short, it seems you get this behavior because std::basic_ostream
provides overloads for char*, signed char* and unsigned char* arguments,
but relies on general operator<< template for wchar_t*. With the
template the argument must match exactly. It doesn't, so you get the
void const* overload.
last para.
Darned keybaord.
A: Because it messes up the order in which people normally read text.
A: Top-posting.