2

I'm trying to create a tabbed window by reading from a ValueTree in JUCE.

I'm using the below code to set the corresponding tab's root item to a child of the tree (full code available here). However, I get the error:

"Member function 'getValueTree' not viable: 'this' argument has type 'const GlobalValueTree', but function is not marked const".

I am using an object as the tree returned by getValueTree() or the function itself are non-static.

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

Can somebody point me in the right direction as to why this is incorrect and how to go about fixing it?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Jefferson
  • 421
  • 5
  • 17

1 Answers1

4

I get the error "Member function 'getValueTree' not viable: 'this' argument has type 'const GlobalValueTree', but function is not marked const"

This is because w is const but the method getValueTree can work only on non-const DataSelectorWindow objects.

If the DataSelectorWindow object was written by you, and you think that getValueTree() should be allowed to be called on const objects, change its prototype to:

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

If the DataSelectorWindow object was written by someone else, your AccelerometerPage c'tor should receive a non-const DataSelectorWindow&, like this:

AccelerometerPage (DataSelectorWindow& w) {
    ...
}
Daniel Trugman
  • 8,186
  • 20
  • 41