我目前正在使用 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 );
然后我得到以下错误信息
error: conversion from 'osg::Uniform*' to non-scalar type 'std::unique_ptr' requested
知道发生了什么事吗?对智能指针有什么要求吗?
最佳答案
你应该这样做:
std::unique_ptr<osg::Uniform> SineUniform(new osg::Uniform( "Sine", 0.0f ));
另外,注意不要混用不同类型的智能指针。 OpenSceneGraph 可能会对其对象的管理方式做出假设,并且可能需要使用 osg::ref_ptr
来代替。您应该通过文档来找出这一点 - 很遗憾,我对此无能为力。
关于c++ - 使用 std c++11 智能指针转换为非标量类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16364637/