I have following code:
class IList{
public:
virtual const Pair *get(const char *key) const = 0;
inline const Pair *operator[](const char *key) const;
};
inline const Pair *IROList::operator[](const char *key) const{
return get(key);
}
代码编译成功,但当我尝试使用它时:
IList *list = (IList *) SomeFactory();
Pair *p;
p = list["3 city"];
I got:
test_list.cc:47:19: error: invalid types ‘IList*[const char [7]]’ for array subscript
p = list["3 city"];
^
我可以理解数组下标可以是int或char,但是std::map如何处理char* /字符串呢?
list
的类型是什么? - NathanOliver