c++ - JUCE - 成员函数不可行 : 'this' Argument Has Type const

标签 c++ compiler-errors constants juce

我正在尝试通过读取 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"

这是因为 wconst,但方法 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/

相关文章:

c++ - 从派生结构初始化 const 父结构成员

ios - swift 1.2 上的 RACCommand 编译失败

exception - 捕获 block 避免编译错误?

c++ - 指向限定和非限定类型表示的指针

c++ - 如果我的函数是常量,那么参数也必须是常量吗?

c++ - 使用大括号括起来的初始化列表初始化一个类

c++ - 函数返回的增量指针

c++ - 1>链接: fatal error LNK1104: cannot open file 'MSCOREE.lib' `

c - const char* 和 char* 转换(ADPCM 解码)

c++ - GEM框架,还是来研究一下GCC吧