【问题标题】:How to read boost variable with type std::vector<std::vector<boost:any>>?如何读取 std::vector<std::vector<boost:any>> 类型的 boost 变量?
【发布时间】:2019-10-12 21:50:53
【问题描述】:

在 Qt creator 中,我可以读取我想在我的代码中使用的变量(屏幕截图中“hold”前面的变量)。 但是我不能将它存储在变量中。

我已经尝试过使用这种语法,但它不起作用:

int maVar = boost::any_cast<int>(_myCUBParam->m_ValueVect[0])

【问题讨论】:

  • 我认为将图片放在您的问题中是个好主意。问题是您放置的链接将来可能不可用。
  • 您应该在问题中包含minimal reproducible example。请不要链接,请不要链接到图片
  • 屏幕截图显示您需要 2 个[0] 才能访问boost::any。你为什么只使用 1 个?
  • @arsdever 他的声望不够。
  • @L.F.对不起。我不知道上传图片需要最低声望。

标签: c++ boost


【解决方案1】:

谢谢@mch。我觉得有点愚蠢,因为它只是缺少的第二个[0]... 当我用maVar = boost::any_cast&lt;int&gt;(_myCUBParam-&gt;m_ValueVect[0][0]) 监视maVar 时,不显示值(而是显示&lt;optimized out&gt;)。 但是,当我在 csv 文件中打印 maVar 时,值会正确打印。

非常感谢您的帮助

【讨论】:

    猜你喜欢
    • 2017-02-01
    • 1970-01-01
    • 2011-09-17
    • 1970-01-01
    • 2018-07-24
    • 1970-01-01
    • 2014-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多