【发布时间】:2023-04-05 09:29:01
【问题描述】:
我有一个 OpenGL 项目的问题,从 void* 指针转换为 shared_ptr<mytype>。
我正在使用 Bullet 在刚体上设置指针:
root_physics->rigidBody->setUserPointer(&this->root_directory->handle);
句柄的类型为shared_ptr<mytype>。
void* 指针由 Bullet 的库函数 getUserPointer() 返回:
RayCallback.m_collisionObject->getUserPointer()
要转换回mytype,static_cast 不起作用:
std::shared_ptr<disk_node> u_poi = static_cast< std::shared_ptr<disk_node> >( RayCallback.m_collisionObject->getUserPointer() );
编译时的错误:
/usr/include/c++/4.8/bits/shared_ptr_base.h:739:39: error: invalid conversion from ‘void*’ to ‘mytype*’ [-fpermissive]
知道如何将getUserPointer() 返回的void* 转换为shared_ptr<mytype>?
【问题讨论】:
标签: c++ pointers casting shared-ptr