使用std c ++ 11智能指针转换为非标量类型

时间:2013-05-03 17:35:02

标签: c++ c++11 unique-ptr openscenegraph

我目前正在使用openscenegraph,它使用自己的智能指针。但我想使用std c ++ 11智能指针。

现在这是工作示例代码

osg::ref_ptr<osg::Uniform> SineUniform   =  new osg::Uniform( "Sine", 0.0f );

但是当我做这样的事情时

std::unique_ptr<osg::Uniform> SineUniform   =  new osg::Uniform( "Sine", 0.0f );

然后我收到以下错误消息

  

错误:从'osg :: Uniform *'转换为非标量类型   请求'std :: unique_ptr'

知道发生了什么事吗?对智能指针有一些要求吗?

1 个答案:

答案 0 :(得分:6)

你应该这样做:

std::unique_ptr<osg::Uniform> SineUniform(new osg::Uniform( "Sine", 0.0f ));

另外,请注意不要混用不同类型的智能指针。 OpenSceneGraph可以对其对象的管理方式进行假设,可能需要使用osg::ref_ptr。你应该通过文档来找到它 - 不幸的是我无法帮助你。