reinterpret_cast从类型'const char*'到类型'__FlashStringHelper*'的转换去除了限定符。

4
我想在AVR Studio中使用Adafruit_CC3000 Arduino库。 我遵循了说明,以在AVR Studio中使用Adafruit arduino库,以便我可以使用其他AVR函数。 但我在编译代码时会出现相同的错误50次。

错误5 reinterpret_cast从类型“const char *”到类型“__FlashStringHelper *”强制转换限定符E:\ arduino-1.0.1 \ libraries \ Adafruit_CC3000 \ Adafruit_CC3000.cpp 183 3 ATmega32_WSClient_CC3K

我已经在网上搜索了这种类型的错误。 但我没有理解问题所在。 我希望你能让我明白这段代码中哪些内容导致了这个错误?

1
你不能使用 reinterpret_cast 来去除 const 限定符,只能使用 const_cast - Some programmer dude
1个回答

15

reinterpret_cast 可以在不同的指针类型之间进行转换,但无法删除 constvolatile 限定符。你需要使用 const_cast

可以采取以下选项(按升序排列):

  • 一开始就不要使用错误的指针类型;
  • 如果您不需要修改对象,请将其强制转换为 const __FlashStringHelper*
  • 如果您需要修改它,请从 char* 进行转换;
  • 如果您坚持完全放弃类型系统,可以使用 reinterpret_cast<__FlashStringHelper*>(const_cast<char*>(whatever)) 或蛮力法 (__FlashStringHelper*)whatever

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接