【问题标题】:JUCE - Member Function Not Viable: 'this' Argument Has Type constJUCE - 成员函数不可行:“this”参数的类型为 const
【发布时间】:2017-10-17 10:45:07
【问题描述】:

我正在尝试通过从 JUCE 中的 ValueTree 中读取来创建一个选项卡式窗口。

我正在使用以下代码将相应选项卡的根项设置为树的子项(完整代码可用here)。但是,我得到了错误:

“成员函数 'getValueTree' 不可行:'this' 参数的类型为 'const GlobalValueTree',但函数未标记为 const”。

我使用一个对象作为getValueTree() 返回的树,或者函数本身是非静态的。

AccelerometerPage (const DataSelectorWindow& w)
{
    tree.setRootItem (rootItem = new const OscValueTreeItem
    (w.valueTree.getValueTree()->getChildWithName ("AccData")));
}

谁能指出我正确的方向,为什么这是不正确的以及如何解决它?

【问题讨论】:

    标签: c++ compiler-errors constants juce


    【解决方案1】:

    我收到错误“成员函数 'getValueTree' 不可行:'this' 参数的类型为 'const GlobalValueTree',但函数未标记为 const”

    这是因为 wconst 但方法 getValueTree 只能在非常量 DataSelectorWindow 对象上工作。

    如果 DataSelectorWindow 对象是您编写的,并且您认为应该允许在 const 对象上调用 getValueTree(),请将其原型更改为:

    <return-value> getValueTree(<params>) const {
        ...
    }
    

    如果 DataSelectorWindow 对象是由其他人编写的,您的 AccelerometerPage c'tor 应该收到一个非常量 DataSelectorWindow&amp;,像这样:

    AccelerometerPage (DataSelectorWindow& w) {
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-07
      • 2015-12-07
      • 2023-03-14
      • 1970-01-01
      • 2018-05-20
      • 2020-09-29
      • 2014-10-18
      • 2013-05-07
      相关资源
      最近更新 更多