amorlzu / pugixml

Automatically exported from code.google.com/p/pugixml
0 stars 0 forks source link

About const char_t* #185

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi !

The method child_value() yields a const char_t* type information. I would like 
to store in a attribute of a class which is a char_t* attribute. The compiler 
doesn't want to convert from const char_t* to char_t when writing:

char_t* c = node.child_value();

How can I proceed ?

Original issue reported on code.google.com by fmichel....@gmail.com on 14 Oct 2012 at 1:00

GoogleCodeExporter commented 9 years ago
You have two options.

1. Change the class field type to const char_t*
2. Violate const-correctness by casting: char_t* c = 
const_cast<char_t*>(node.child_value()).

Note that actually changing data that the pointer c points to will work (it 
will change the value of a PCDATA node in the document), but is not defined 
(i.e. no guarantee that a future version of pugixml will not break this). Also, 
obviously, trying to increase the size of the value will lead to more undefined 
behavior (i.e. writing more bytes to c than the value of strlen(c)).

If you want a supported way to change the child value, you can do

node.text().set("...");

Original comment by arseny.k...@gmail.com on 14 Oct 2012 at 10:47