如何使用libconfini静态回调为类变量赋值



我正在用C++编写一个类,用于读取.ini文件,并将其所有条目填充到一个私有变量(vector iniEntries(中。然而,在libconfini中,我注意到我们需要实现一个静态回调函数并使用它的调度器,以便从.ini文件中获得每个key=值。

通过使用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]"的引用

您的问题不是很清楚。但这个库似乎有一个C++类的例子,可以或多或少地做你想做的事情(map.cpp和map.hpp(,你为什么不从编辑它开始呢?

最新更新