Fadecomic
Fadecomic

Reputation: 1268

Get a pointer to a subordinate YAML::Node

I am writing a config file library, and I'd like to have a pointer to a sub-node to pass to functions expecting YAML::Node*, for example for building up a YAML document.

I can create a new Node and get a pointer easily enough:

YAML::Node* foo = new YAML::Node(); // Null node

and I can add a new sub node easily enough:

(*foo)["bar"] = baz; 

However, I don't know how to get a pointer to (*foo)["bar"]. If I try

&((*foo)["bar"]);

I get error: taking address of temporary, which is true, because the [] operator returns a YAML::Node. Is there a way to get a pointer to (*foo)["bar"] so that I can pass it to something like

void f(YAML::Node* const blah) 
{
    (*blah)["banana"] = 1;
}

which is useful, because then I can build up a tree with recursive calls to f.

Upvotes: 1

Views: 1014

Answers (1)

Jesse Beder
Jesse Beder

Reputation: 34054

Just pass a YAML::Node, not a pointer. YAML::Node is already a reference type, so you can pass it like a pointer.

Upvotes: 2

Related Questions