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* (); ...
在主要功能的某个地方: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* (); ...,c++,C++,在主要功能的某个地方: 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': can
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"
我做错了什么?您需要一个用于
wchar\u t*
的构造函数
String(const wchar_t*);
您需要
wchar\u t*
的构造函数
String(const wchar_t*);
三行“主目录中的某处”都没有使用赋值,所以
我们可以忽略您可能定义的任何赋值运算符。
您还没有定义转换构造函数,它需要
单参数(awchar\u t const*
),用于转换wchar\u t
常数*
三行“主要位置”中没有一行使用赋值,所以
我们可以忽略您可能定义的任何赋值运算符。
您还没有定义转换构造函数,它需要
单参数(awchar\u t const*
),用于转换wchar\u t
常数*
详细说明:赋值运算符不足。这只适用于赋值(字符串y;y=x;
)。初始化不是赋值,即使它使用相同的=
符号。详细说明:赋值运算符不够。这只适用于赋值(字符串y;y=x;
)。初始化不是赋值,即使它使用相同的=
符号。