本文介绍了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 ++通过智能指针的向量迭代
发布评论