我有一个具有此功能的类:
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 类当然具有该功能,但位于不同的头文件中。 这是什么原因?
最佳答案
你不是说
(*i)->RenderShape(destination);
?
i
是迭代器,*i
是shared_ptr
,(*i)::operator->()
是对象。
关于C++ 遍历智能指针 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11960631/