При разборе файла yaml обычно мы получаем корневой узел из парсера.
И мне интересно, могу ли я ссылаться на корневой узел после процесса синтаксического анализа.Как показано ниже.
YAML::Node* globalRoot;
void ParseDocument(filename)
{
YAML::Parser parser(fin)
parser.GetNextDocument(*globalRoot);
}
void myFunction()
{
ParseDocument("myYAML.yml");
// After the method above, we lose the parser instance since it's a local variable.
// But if all child data is copied, below code should be safe.
// If globalRoot is just pointing inside the parser, this could be dangerous.
std::string stringKey;
(*globalRoot)["myKey"] >> stringKey;
}
Могу ли я использовать как код выше ??