Conversion to non-scalar type with std c++11 smart pointer

↘锁芯ラ 提交于 2019-12-12 13:28:18

问题


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.

now this is the working example code

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

but when I do something like this

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

Then I get the following error message

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?


回答1:


You should do this:

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

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.



来源:https://stackoverflow.com/questions/16364637/conversion-to-non-scalar-type-with-std-c11-smart-pointer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!