【问题标题】:How to use libconfini static callback to assign a value into class variable如何使用 libconfini 静态回调为类变量赋值
【发布时间】: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]' 的未定义引用

【问题讨论】:

    标签: c++ parsing static ini


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-01
      • 2016-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-18
      • 2015-01-11
      • 1970-01-01
      相关资源
      最近更新 更多