Re: [xml] xmlChar double ptr

how do i define a double ptr xmlChar? is it possible at all?
static xmlChar* mapper[] = {"bla", "blubber"} ;

doesn't work. g++ says
XMLStructure.h:75: error: invalid conversion from ?const char*? to

There's 2 problems here:
One is that, under many configurations of g++, quoted strings are of type
"const char []", which will coerce to "const char *". Since you are
assigning them to a non-const pointer, this is a const-ness violation.
Changing your variable to "const xmlChar *" (or better still "const
xmlChar * const") would help this.

(BTW: in C++ "const" implies "static". Also, making the array of pointers
itself constant is good practice, hence my recommendation of "const
xmlChar * const")

The second is that "xmlChar" is actually "unsigned char", so you are again
crossing a type, and that will ALSO be an error.

The best way around this would be to cast the strings, thus:
const xmlChar *const mapper[] =
  reinterpret_cast<const xmlChar *>("bla"),
  reinterpret_cast<const xmlChar *>("blubber")

You could also use the libxml2 "BAD_CAST" macro:
const xmlChar *const mapper[] =
  BAD_CAST "bla",
  BAD_CAST "blubber"

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]