怎么搞错了?
-配置h
class Config: {
public:
void read();
std::string operator[](std::string key);
....
};
-- app.cpp
Config *config;
config->read();
std::string a=config["sysname"]; // this line error
发布于 2014-05-04 14:34:32
config
是一个指针,所以在语法上调用它的operator[]
的方法应该是
(*config)["sysname"]
或
config->operator[]("sysname")
造成混淆错误消息的原因是,对指针调用operator[]
在语法上是正确的,但是参数是一个整体类型:
int* p;
p[42];
注意,在您的代码中,config
没有指向有效的Config
对象。
https://stackoverflow.com/questions/23457437
复制相似问题