Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - implementing string class using std namespace string: (2 Items)
   
implementing string class using std namespace string  
Hi, 
I made a string class for wide characters. 
this is the code - 

using namespace std; 
class MyString 
{ 
public: 
wstring wStr; 
MyString () {wStr = L"";} 
MyString (wstring str) {wStr = str;} 
}; 

int main() 
{ 
wstring firstName = L"Vipul"; 
MyString myStr (firstName); 
wprintf(L"%s", myStr.wStr); 
return 0; 
} 

But it gives error - cannot pass objects of non-POD type class std::wstring through '...'; call will abort at runtime. 

What are POD type classes and non-POD type classes? 
And how to solve this? I want to make my string class platform independent. 

Thanks,
RE: implementing string class using std namespace string  
You'll want to use:

 wprintf(L"%s", myStr.wStr.c_str());

thus passing the wchar_t pointer you really want to pass to wprintf.
There's no automatic conversion from a wstring to a wchar_t * and even
if there was the compiler would not know to apply it since functions
such as wprintf that take variable arguments don't provide any type
information them. 

A POD type (Plain Old Data) is essentially just a C struct.

So far as I know this is all part of the C++ standard and so will
(should) be platform independent.