问题描述
我目前正在玩opencenegraph,它使用自己的智能指针。但我想使用std c ++ 11智能指针。
I am currently playing around with openscenegraph and it uses its own smart pointer. But I want to use the std c++11 smart pointer.
现在这是工作示例代码
osg::ref_ptr<osg::Uniform> SineUniform = new osg::Uniform( "Sine", 0.0f );
但是当我这样做时
std::unique_ptr<osg::Uniform> SineUniform = new osg::Uniform( "Sine", 0.0f );
然后我得到以下错误信息
Then I get the following error message
任何想法发生了什么?对于智能指针有一些要求吗?
Any idea what is going on? Are there some requirements for smart pointers?
推荐答案
您应该这样做:
std::unique_ptr<osg::Uniform> SineUniform(new osg::Uniform( "Sine", 0.0f ));
此外,注意不要混合不同类型的智能指针。 OpenSceneGraph可以假设它的对象是如何管理的,并且可能需要使用 osg :: ref_ptr
。你应该通过文档找到这一点 - 我不能帮助那不幸的。
Also, be careful not to mix different types of smart pointers. OpenSceneGraph may make assumptions on how its objects are managed, and may require using osg::ref_ptr
instead. You should go through the documentation to find this out - I cannot help with that unfortunately.
这篇关于使用std c ++ 11智能指针转换为非标量类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!