所以我有这个:
class Grup : public Shape
{
private:
std::vector<Shape *> continut;
public:
static const std::string identifier;
Grup(){};
~Grup(){
continut.clear();
};
void add(Shape *);
void remove(Shape *);
void output(std::ostream &) const;
void readFrom(std::istream &);
void moveBy(int, int);
friend std::ostream &operator<<(std::ostream &, const Grup &);
}
我想实现删除功能。我试过这个:
void Grup::remove(Shape *s)
{
vector<Shape*>::iterator it;
it = continut.begin();
while(it!=continut.end())
{
if((*it) == s)
{
it = continut.erase(it);
}
else it++;
}
}
但是 == 并没有给我一个真正的价值。我还尝试在每个形状上重载运算符 == 但结果相同。我能做些什么?