小编Ale*_*etu的帖子

如何将void*转换为shared_ptr <mytype>

我有一个OpenGL项目的问题,从void*指针转换为shared_ptr<mytype>.

我正在使用Bullet在刚体上设置指针:

root_physics->rigidBody->setUserPointer(&this->root_directory->handle);
Run Code Online (Sandbox Code Playgroud)

手柄属于类型shared_ptr<mytype>.

void*指针由子弹的库函数返回,getUserPointer():

RayCallback.m_collisionObject->getUserPointer()
Run Code Online (Sandbox Code Playgroud)

要转换回mytype,static_cast不起作用:

std::shared_ptr<disk_node> u_poi = static_cast< std::shared_ptr<disk_node> >( RayCallback.m_collisionObject->getUserPointer() );
Run Code Online (Sandbox Code Playgroud)

错误,在编译时:

/usr/include/c++/4.8/bits/shared_ptr_base.h:739:39: error: invalid conversion from ‘void*’ to ‘mytype*’ [-fpermissive]
Run Code Online (Sandbox Code Playgroud)

知道如何从void*返回的转换getUserPointer()shared_ptr<mytype>

c++ pointers casting shared-ptr

3
推荐指数
1
解决办法
5924
查看次数

标签 统计

c++ ×1

casting ×1

pointers ×1

shared-ptr ×1