我正在尝试学习C++,我不明白为什么以下代码不起作用:
class String
{
public:
String();
String(const String& other);
String& operator = (const String& other);
String& operator = (const wchar_t* other);
String& operator () (const wchar_t* other);
~String();
operator const wchar_t* ();
...
Run Code Online (Sandbox Code Playgroud)
在主要功能的某处:
wchar_t* x = L"A test string";
String y = (String)x; //not working
String z = x; //not working
Run Code Online (Sandbox Code Playgroud)
VC++编译器告诉我这个:
Error 1 error C2440: 'type cast': cannot convert from 'wchar_t *' to 'String'
Error 2 error C2440: 'initializing': cannot convert from 'wchar_t *' to 'String'
IntelliSense: no …Run Code Online (Sandbox Code Playgroud) c++ ×1