我正在尝试学习 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* ();
...
在 main 函数的某处:
wchar_t* x = L"A test string";
String y = (String)x; //not working
String z = x; //not working
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 suitable constructor exists to convert from "wchar_t *" to "String"
我究竟做错了什么?