0

我在 CppLint 上遇到了这个错误:

Using C-style cast.  Use reinterpret_cast<xmlChar *>(...) instead  [readability/casting] [4]

当我尝试投射这样的东西时:

xmlChar* something = (xmlChar*) anOtherThing;

但如果我这样做:

xmlChar* something = reinterpret_cast<xmlChar *>(anOtherThing);

我在构建时遇到此错误:

error: reinterpret_cast from type ‘const char*’ to type ‘xmlChar*’ casts away constness

请问你能帮帮我吗 ?

4

1 回答 1

0

所以解决方案是像 Vivick 说的那样用 const xmlChar* 替换 xmlChar* 。

但是,如果我们像我一样使用 xmlChar*,我们可以使用函数 xmlChartStrdup() 而不是 reinterpret(),它避免了将所有代码更改为 const。

谢谢大家

于 2018-08-06T14:21:53.000 回答