As I understand getChild does not return reference, so how to get reference to deeply nested sub-tree,
I want to avoid spaghetti like this
tree.getChildWithName(“first”).getChildWithName(“second”).getChildWithName(“third”).
ValueTrees are “reference-like” objects, so for example getChild returns an instance where changes to it happen also to the “original” tree.
ValueTree maintree("root");
ValueTree childtree("child1");
childtree.setProperty("x", 42, nullptr);
maintree.addChild(childtree, -1, nullptr);
{
ValueTree temp = maintree.getChild(0);
temp.setProperty("x", 1001, nullptr);
// even though "temp" is destroyed here, the change was already
//applied also to the original tree
}
// prints 1001 twice
std::cout << (int)childtree.getProperty("x") << "\n";
std::cout << (int)maintree.getChild(0).getProperty("x") << "\n";
1 Like
Thanks, you’re right.
I was doing something in constuctor while original tree not yet exist.