gpt4 book ai didi

C++ 遍历智能指针 vector

转载 作者:可可西里 更新时间:2023-11-01 15:37:59 28 4
gpt4 key购买 nike

我有一个具有此功能的类:

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 是迭代器,*ishared_ptr(*i​​)::operator->() 是对象。

关于C++ 遍历智能指针 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11960631/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com