我注意到了类似于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