从 'const char*' 型到'__FlashStringHelper*'型的reinterpret_cast会丢弃限定符
reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away qualifiers
我想在AVR Studio中使用Adafruit_CC3000 arduino库。我已经按照这个说明将Adafruit arduino lib与AVR工作室一起使用,所以我也可以使用其他AVR功能。但是我在编译代码时遇到相同的错误 50 次。
错误 5 从类型"const char*"reinterpret_cast为类型 "__FlashStringHelper*"被抛弃 限定符 E:\arduino-1.0.1\libraries\Adafruit_CC3000\Adafruit_CC3000.cpp 183 3 ATmega32_WSClient_CC3K
我在网上搜索过这种错误。 但我未能理解这个问题。我要求让我了解此代码中的哪件事会产生此错误?
reinterpret_cast
可以在不相关的指针类型之间进行转换,但不能删除const
或volatile
限定符。为此,您需要const_cast
。
选项是(大致按增加的顺序):
- 首先不要使用错误的指针类型;
- 投射到
const __FlashStringHelper*
,如果你不需要修改对象; - 从
char*
转换,如果你确实需要修改它; - 如果您坚持完全放弃类型系统,请使用
reinterpret_cast<__FlashStringHelper*>(const_cast<char*>(whatever))
或蛮力(__FlashStringHelper*)whatever
。
相关文章:
- 如何理解C++标准N3337中的expr.const.cast子句8
- C++Cast运算符过载
- 错误:"cast"未命名类型void setCastDescription(std::string
- 通过使用 const-cast 的非常量引用来延长临时的寿命
- "(void) cast"与功能有什么区别 "__attributes__"来沉默未使用的参数警告?
- C++:"Expected '(' for function-style cast or type construction"错误
- 为什么选择 g++ 给予者:"error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]"
- Gtk+ g_signal_connect() 和 C++ lambda 会导致"invalid cast"错误
- Shared_ptr cast vs static_cast speed
- 在 iOS 上使用 Aruco 构建 OpenCV 时"Functional-style cast from id to double is not allowed"
- 覆盖 CAST 运算符(我认为它被称为向下转换)
- C++错误,隐 <function-style-cast> 式要求使用模板化类一次调用多个构造函数的多个转换
- 如何修复<function-style-cast>错误:无法从'initializer list'转换为asdending比较<W>(模板函子)
- C++ C++ 中的函数声明,键入 CAST
- static_cast会丢弃错误,但C风格的演员cast有效
- C++ cast char * to unsigned char
- 禁用 Clang 中的"cast from pointer to smaller type uint32_t"错误
- 是否可以使用gcc 3.3版修复与int*cast相关的Sun Solaris OS 5.8分段故障
- C++ const-cast 一个引用
- 错误 C2440: 'type cast':无法从 'bool' 转换为 'CString'