如何解决如何使用libconfini静态回调将值分配给类变量
我正在用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]”的未定义引用
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。