在C ++中创建列表时出错

时间:2014-06-05 20:46:58

标签: c++ list build console makefile

我正在尝试用c ++创建一个列表,但是在我构建代码时它给了我错误。

以下是我创建自定义列表的代码:

std::list< osg::ref_ptr<osg::PositionAttitudeTransform> > bulletList = new std::list< osg::ref_ptr<osg::PositionAttitudeTransform> > ;

控制台上的错误说明了这一点:

错误:从‘std::list<osg::ref_ptr<osg::PositionAttitudeTransform> >*’转换为非标量类型‘std::list<osg::ref_ptr<osg::PositionAttitudeTransform> >’请求

我该怎么做?

3 个答案:

答案 0 :(得分:2)

正如我的评论所说,C ++不是Java。

所有你需要的是:

std::list< osg::ref_ptr<osg::PositionAttitudeTransform> > bulletList;

如果出于某种原因你真的想动态创建一个列表,那么你可以使用一个指针。

std::list< osg::ref_ptr<osg::PositionAttitudeTransform> >* bulletList = new std::list< osg::ref_ptr<osg::PositionAttitudeTransform> >();

然后你现在头疼的是确保调用delete,否则会发生内存泄漏。

答案 1 :(得分:1)

您正在创建一个std :: list&lt; ...&gt;不是std :: list&lt; ...&gt; *所以没有理由使用new来为它分配存储空间。编译器会为你做这件事。

答案 2 :(得分:-2)

问题解决了将“*”添加到List的声明中,C ++非常讨厌lol