无法投射为无效 *
can't cast to void *
本文关键字:无效 更新时间:2023-10-16
class MyClass {
public:
register_callback(int, void*);
}
typedef boost::shared_ptr<MyClass> myClass_p;
class MyOtherClass {
public:
registerItem(std::pair<std::string, myClass_p>insertItem) {
auto foo = insertItem.second;
void *bar = static_cast<void*>(foo);
}
鉴于上面的代码,为什么我得到"static_cast:无法从 myClass_p 转换为 void *。 我以为你可以将任何指针投射到一个空隙*。
foo
不是指针。它是一个对象。该对象恰好是一个boost::shared_ptr<MyClass>
,因此在语义上是一个智能指针。但这不是一个指针。
假设你正在做的事情是有意义的可疑假设,你需要:
void *bar = foo.get();
boost::shared_ptr<MyClass>::get()
返回指向共享对象的指针(如果为空,则返回nullptr
(。
相关文章:
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 无法访问嵌套类.类的使用无效
- 如果用户输入无效,如何使用字符串变量-C++重复输入命令
- 如何解决错误:SCIP C++中的 SCIP 阶段无效 <10>
- 在没有参数列表的情况下使用模板名称"Event"无效,模板问题
- FFMPEG配置文件级别id大小无效
- 错误:从"int"到枚举c++的转换无效
- 如何修复此错误:className::className的无效使用
- 为什么将值返回函数传递给重载=运算符对运算符函数有效,而对其他运算符无效
- C++-模板嵌套类的引用初始化无效
- 错误:无效的预处理指令 #i 的意思是 #if?
- 多维数组 C++ 中数组下标的类型"int[int]"无效
- 在 C++ 中使用正则表达式错误时出现问题 括号表达式中的范围无效
- 从 'int' 到 'int*' CPP 的转换无效
- 如何接受 [ENTER] 键作为无效输入并发送错误消息
- 由于无效的 ValidateRgn() 子窗口不会收到WM_PAINT消息
- C++ PTHREADS - 无效转换无效*(*)()到无效*(*)(无效*)
- 声明为无效的变量或字段'...' Ardunio 编译器上的错误
- 数组下标的类型"float*[float]"无效
- 修改 std::vector 会使迭代器无效吗?