使用std c ++ 11智能指针转换为非标量类型 [英] Conversion to non-scalar type with std c++11 smart pointer

查看:844
本文介绍了使用std c ++ 11智能指针转换为非标量类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在玩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


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

error: conversion from 'osg::Uniform*' to non-scalar type 'std::unique_ptr' requested

任何想法发生了什么?对于智能指针有一些要求吗?

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智能指针转换为非标量类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆