I am using the rapidxml lib.
It defines a function to parse files in this way:
template<int Flags>
void parse(Ch *text)
The lib provides const int flags for example:
const int parse_declaration_node = 0x20;
So I created a pointer to a static int in my class:
const int * parser_mode;
And in the class constructor I assigned it its value:
parser_mode = &rapidxml::parse_declaration_node;
Then when I try to use this const int * as template argument to the parse function:
tree->parse<parser_mode>(file->data());
I get this error message:
error: ‘GpxSectionData::parser_mode’ cannot appear in a
constant-expression
This rest of the statement seems correct since:
tree->parse<0>(file->data());
doesn’t produce compilation error…
Could you please tell me what I am missing here?
Thank you!
Thanks to the explanations below I will probably define it out of the class:
So I think this is:
class Myclass {
static const int parser_mode;
[...]
}
static const int Myclass::parser_mode = rapidxml::parse_declaration_node;
template<int Flags> void parse(Ch *text)…const int * parser_mode;Your template takes an
intas a template parameter, but you are passing it anint*. The typesintandint*are not the same.Try
tree->parse<rapidxml::parse_declaration_node>(file->data());