<分区>
我想使用 [] 运算符获取和设置测试类对象的值。但是出现以下错误:
lvalue required as left operand of assignment
提前致谢。
class Candidate {
public:
Candidate(string name):
name(name) {}
string name;
};
template<typename _key, typename _value>
class Test {
_key key;
_value value;
public:
_value operator[](_key key) {
return this->value;
}
};
int main() {
Test<string, Candidate*> test;
test["something"] = new Candidate("name");
Candidate* candidate = test["something"];
return 0;
}