【发布时间】:2012-08-14 20:58:14
【问题描述】:
我有一个具有此功能的类:
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吗?为什么不for (vector<sp_PrimShapeBase>::iterator i = LineVector.begin()或者更好的for (auto it = LineVector.begin()?
标签: c++ stl vector smart-pointers