Each time you call GetWideString()
, you are creating a new std::wstring
, which has a newly allocated memory buffer. You are comparing pointers to different memory blocks (assuming Assert::AreEqual()
is simply comparing the pointers themselves and not the contents of the memory blocks that are being pointed at).
Update: const wchar_t* wchar2 = GetWideString("me").c_str();
does not work because GetWideString()
returns a temporary std::wstring
that goes out of scope and gets freed as soon as the statement is finished. Thus you are obtaining a pointer to a temporary memory block, and then leaving that pointer dangling when that memory gets freed before you can use the pointer for anything.
Also, const wchar_t* wchar2 = GetWChar("me");
should not compile. GetWChar()
returns a std::wstring
, which does not implement an implicit conversion to wchar_t*
. You have to use the c_str()
method to get a wchar_t*
from a std::wstring
.