gpt4 book ai didi

C++ 最近的转换错误

转载 作者:行者123 更新时间:2023-11-30 02:47:20 25 4
gpt4 key购买 nike

在维护使用 libmxl2 的旧代码时,出现以下错误:

error: invalid static_cast 
from type ‘const char [8]’
to type ‘xmlChar* {aka unsigned char*}’

在下面的代码中:

xmlNodePtr messageNode = doc->children; // The "Message" node
if(xmlStrcmp(messageNode->name, static_cast<xmlChar*>("Message"))) ... blabla

(同样的错误发生在reinterpret_cast)

显然,我可以使用旧式转换 (xmlChar*) 来解决,但最近在 C++ 中执行此操作的正确方法是什么?

我用的是gcc 4.7.2(这段代码是5年前编译的:)没有这个错误,但不要问旧编译器的版本:))

最佳答案

经过一些转换组合之后,这个工作:

const_cast<xmlChar*>(reinterpret_cast<const xmlChar *>("Message"))

关于C++ 最近的转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22838802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com