I want to create a class in C ++. This class must manage the collection. OK, no problem, I would like to use the [] operator, of course, but in this case my desire is not to index by position, but by name ==>, this means using a row indexer.
Something like this seems not so good for my compiler:
class myclass {
...
...
std::string operator[](const std::string& name);
}
std::string myclass::operator[](const std::string& name) {
...
}
myclass m;
std::string value = m["Name"];
The compiler tells me that it cannot solve this because the [const char [5]] operator does not exist. alright alright I could understand this ... The compiler thinks that by calling m ["Name"], I am trying to call an operator that allows char * rather than a string ... ok Let me change the code using the [] operator, allowing char * as a parameter ... nothing.
- , ++ ? , , ...
.