我注意到了類似於C++中的內容。通過[「」]或[int]爲自定義類別提供C++訪問組件
SomeClass obj = SomeClass();
int boo = obj["foo"];
這是什麼叫,我該怎麼做?
例如
class Boo {
public:
int GetValue (string item) {
switch (item) {
case "foo" : return 1;
case "apple" : return 2;
}
return 0;
}
}
Boo boo = Boo();
int foo = boo.GetValue("foo");
// instead of that I want to be able to do
int foo = boo["foo"];
您無法打開字符串。 – Mankarse 2012-02-16 01:56:34
@Mankarse:好點。固定。謝謝。 – 2012-02-16 02:06:55