【发布时间】:2021-02-17 12:00:53
【问题描述】:
我正在用 C++ 编写一个类,用于读取 .ini 文件并将其所有条目填充到私有变量(向量 iniEntries)中。但是,在 libconfini 中,我注意到我们需要实现一个静态回调函数并使用它的调度程序来从 .ini 文件中获取每个 key=value。
我的回调函数,使用libconfini,如下图所示:(请注意,这个回调是tINIParser类中的static,它必须是libconfini要求的!)
int tINIParser::callback(IniDispatch * dispatch, void * v_other)
{
string data = dispatch->data;
string value = dispatch->value;
// Now to store into
if (dispatch->type==INI_KEY)
{
// I tried this... (iniKeysTemp and iniValuesTemp are private in tINIParser and non-static but I also tried to use static)
iniKeysTemp = data;
iniValuesTemp = value;
// And also this with vectors... (iniKeys and iniValues are private in tINIParser and non-static but I also tried to use static)
iniKeys.push_back(data);
iniValues.push_back(value);
}
return 0;
}
现在的主要问题是:如何将调度值存储到我的 tINIParser 类变量中?我收到链接错误和编译错误,例如:
- 警告:针对
_ZN10tINIParser13iniValuesTempB5cxx11E' in read-only section.text'的重定位 - 在函数`tINIParser::callback(IniDispatch*, void*)'中:
- 未定义对 `tINIParser::iniKeysTemp[abi:cxx11]' 的引用
- 对 `tINIParser::iniValuesTemp[abi:cxx11]' 的未定义引用
【问题讨论】: