我正在创建一个C ++应用程序,我有一个包含char
数组变量的类,如下所示:
class MyClass
{
public:
// The constructor
MyClass(char[]);
private:
// The variable
char myVariable[];
}
我尝试在这样的构造函数中设置此变量:
// The constructor
MyClass::MyClass(char myVariable[])
{
// Set the variable
MyClass::myVariable = myVariable; //<----- Error
}
然后我在我设置Error: expression must be a modifiable lvalue
变量的行上收到错误(MyClass::myVariable
)。我是C ++的新手,所以我不知道这意味着什么。任何帮助将不胜感激!
答案 0 :(得分:3)
您无法使用赋值运算符(=
)
您应该#include<algorithm>
并致电以下
std::copy(myVariable, MyClass::myVariable, size_of_muVariable);
否则将成员和参数更改为指针或stl类型为:
char *myVariable;
std::string myVariable;
std::vector<char> myVariable;