CppLint铸造字符*错误

CppLint Cast Char* Error

本文关键字:错误 字符 CppLint      更新时间:2023-10-16

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

你能帮我吗?

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

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

感谢所有