我想学习C++,我不明白为什么下面的代码不工作:构造和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*();
...
某处在主要功能:
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"
我在做什么错?
详细说明:赋值运算符不足。这只会用于赋值('String y; y = x;')。初始化不是赋值,即使它使用相同的“=”符号。 – hvd