我正在尝试通过读取 JUCE 中的 ValueTree 来创建选项卡式窗口。
我使用下面的代码将相应选项卡的根项设置为树的子项(完整代码可用 here )。但是,我收到错误:
"Member function 'getValueTree' not viable: 'this' argument has type 'const GlobalValueTree', but function is not marked const".
我使用一个对象作为 getValueTree()
返回的树,或者函数本身是非静态的。
AccelerometerPage (const DataSelectorWindow& w)
{
tree.setRootItem (rootItem = new const OscValueTreeItem
(w.valueTree.getValueTree()->getChildWithName ("AccData")));
}
有人能指出正确的方向,说明为什么这是不正确的以及如何解决它吗?
最佳答案
I get the error "Member function 'getValueTree' not viable: 'this' argument has type 'const GlobalValueTree', but function is not marked const"
这是因为 w
是 const
,但方法 getValueTree
只能对非 const DataSelectorWindow
对象起作用.
如果 DataSelectorWindow 对象是您编写的,并且您认为应该允许在 const
对象上调用 getValueTree()
,请将其原型(prototype)更改为:
<return-value> getValueTree(<params>) const {
...
}
如果 DataSelectorWindow 对象是由其他人编写的,您的
AccelerometerPage
c'tor 应该接收一个非常量 DataSelectorWindow&
,如下所示:
AccelerometerPage (DataSelectorWindow& w) {
...
}
关于c++ - JUCE - 成员函数不可行 : 'this' Argument Has Type const,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46788261/