C ++通过智能指针的向量迭代

编程入门 行业动态 更新时间:2024-10-23 05:40:01
本文介绍了C ++通过智能指针的向量迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个类有这个功能:

i have a class that has this function:

typedef boost::shared_ptr<PrimShapeBase> sp_PrimShapeBase; class Control{ public: //other functions RenderVectors(SDL_Surface*destination, sp_PrimShapeBase); private: //other vars vector<sp_PrimShapeBase> LineVector; }; //the problem of the program void Control::RenderVectors(SDL_Surface*destination, sp_PrimShapeBase){ vector<sp_PrimShapeBase>::iterator i; //iterate through the vector for(i = LineVector.begin(); i != LineVector.end(); i ++ ){ //access a certain function of the class PrimShapeBase through the smart //pointers (i)->RenderShape(destination); } }

编译器告诉我类boost :: shared_ptr 没有名为RenderShape的成员,我觉得奇怪,因为类PrimShapeBase肯定有这个函数,但是在一个不同的头文件。 这是什么原因?

The compiler tells me that the class boost::shared_ptr has no member called 'RenderShape' which I find bizarre since the class PrimShapeBase certainly has that function but is in a different header file. What is the cause of this?

推荐答案

不是指

(*i)->RenderShape(destination);

i 是迭代器, * i 是 shared_ptr ,(* i):: operator->()是对象。

i is the iterator, *i is the shared_ptr, (*i)::operator->() is the object.

更多推荐

C ++通过智能指针的向量迭代

本文发布于:2023-07-30 00:29:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1244969.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:向量   指针   迭代   智能

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!