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

Mai*_*ein 3 c++ openscenegraph unique-ptr c++11

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

现在这是工作示例代码

osg::ref_ptr<osg::Uniform> SineUniform   =  new osg::Uniform( "Sine", 0.0f );
Run Code Online (Sandbox Code Playgroud)

但是当我做这样的事情

std::unique_ptr<osg::Uniform> SineUniform   =  new osg::Uniform( "Sine", 0.0f );
Run Code Online (Sandbox Code Playgroud)

然后我收到以下错误消息

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

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

And*_*owl 6

你应该做这个:

std::unique_ptr<osg::Uniform> SineUniform(new osg::Uniform( "Sine", 0.0f ));
Run Code Online (Sandbox Code Playgroud)

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