CppLint Cast Char *错误

时间:2018-08-06 13:36:23

标签: c++ char cpplint

我在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

能帮我吗?

1 个答案:

答案 0 :(得分:0)

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

但是,如果我们像我一样使用xmlChar *,我们可以使用xmlChartStrdup()函数代替reinterpret(),这样可以避免更改所有代码以放入const。

谢谢