JUCE - 成员函数不可行:'this'参数具有常量类型

JUCE - Member Function Not Viable: 'this' Argument Has Type const

本文关键字:参数 常量 类型 this 不可行 成员 JUCE 函数      更新时间:2023-10-16

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

我使用以下代码将相应选项卡的根项设置为树的子项(此处提供完整代码)。但是,我收到错误:

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

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

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

有人可以指出我正确的方向,为什么这是不正确的以及如何解决它吗?

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

这是因为w const但方法getValueTree只能对非常量DataSelectorWindow对象起作用。

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

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

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

AccelerometerPage (DataSelectorWindow& w) {
    ...
}