I am trying to write a function that walks through an XML node of variable depth and finds a value. A recursive variadic function seemed like a good solution, so I tried this
struct MiniNode {
std::string getAttributeString(std::string s) {}
MiniNode getChildByKey(std::string s) {}
};
static std::string getFromNodeDefault(MiniNode* node, std::string& def, std::string& key) {
try {
return node->getAttributeString(key);
} catch (...) {
return def;
}
}
static std::string getFromNodeDefault(MiniNode* node, std::string& def, std::string& key, std::string&... args) {
try {
return getFromNodeDefault(node->getChildByKey(key), def, args...);
} catch (...) {
return def;
}
}
But the compiler is complaining that
main.cpp:20:91: error: expansion pattern 'Args&' contains no argument packs main.cpp: In function 'std::string getFromNodeDefault(MiniNode*, std::string&, T&)':
main.cpp:22:67: error: 'args' was not declared in this scope
return getFromNodeDefault(node->getChildByKey(key), def, args...);
I took parts of the second answer here as an example, without using the template as I know my type Variable number of arguments in C++?
Any pointers to what I am doing wrong here?