I would like to get and set the value of Test Class object using [] operator. But getting the following error:
lvalue required as left operand of assignment
Thanks in Advance.
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;
}