Code: Alles auswählen
#include <iostream>
class Test {
public:
std::string& operator[](std::string const & key) {
// irgendwas
std::string* s = new std::string(key);
return *s;
}
};
int main() {
Test const t;
std::string value = t["Hallo Welt"];
std::cout << value << std::endl;
}
nicht umgehen. Btw zeigt sie genau auf die ZeileFehler: Die Übergabe von »const Test« als »this«-Argument von »std::string& Test::operator[](const string&)« streicht Qualifizierer [-fpermissive]
Code: Alles auswählen
std::string value = t["Hallo Welt"];
LG Glocke
/EDIT: Muss ich dann neben
Code: Alles auswählen
T_return& X::operator[](T_index const& index);
Code: Alles auswählen
const T_return& X::operator[](T_index const& index) const;