将auto_ptr转换为无效指针
Casting auto_ptr to void pointer
我正在尝试通过以下方式将auto_ptr转换为无效指针:
void *AM::This2Ctx(std::auto_ptr<AMContext> data)
{
return reinterpret_cast<void *>(data);
}
但是我不断收到编译错误:
error: invalid cast from type std::auto_ptr<AMContext> to type void*
如何正确完成这种铸造?以及如何以相反的方式使用它?
使用 .get()
访问 auto-ptr 持有的指针:
reinterpret_cast<void *>(data.get());
~~~~~~
此外,auto_ptr
已弃用,请改用unique_ptr
。
相关文章:
- 如何实现容纳整数和无效指针的双向链表?
- 在基数排序中,我得到 munmap_chunk():无效指针和中止(核心转储).为什么?
- 应用地址清理器后,免费无效指针消失
- C++ 在具有数组成员的类上无效指针/双精度释放
- 不断得到分段错误和free()无效指针
- 使用无效指针初始化指针声明符的行为是否未定义?
- 结构作为参数的函数产生错误:free():无效指针:0x00007efd47b
- 无效指针、隔离标识符等
- c++ 无效指针从空闲列表中取消排队
- C++ munmap_chunk(): 无效指针:
- 为什么我的简单C++程序使用队列和 fstream 错误到无效指针
- 无效指针和非初始化的指针之间的差异
- 如何用无效指针初始化unique_ptr的向量
- 地址清理器在静态强制转换无效指针时报告错误
- MS4:Free(Free()无效指针0xB74E74E0 ***
- ***检测到的GLIBC *** MS2:free():无效指针:0xB7526FF4 ***
- 无效指针功能的输出
- 有人能告诉我这是如何在main()中实现的吗?(关于无效指针的问题)
- C++11使用智能指针,但得到无效指针
- 无效指针的相关性