I’d like to create an aggregation and store the objects with vector, is it correct which I wrote? :
Class A
{
private:
vector <B *> pB;
public:
A();
A(int tag);
~A();
}
A::A(int tag){
for (i=0; i != tag, i++)
pB.push_back(new B());
}
And to create not an aggregation but a composition I only have to add this in the destructor:
A::~A(){
vector <B *>::iterator citer = pB.begin();
while (citer != pB.end())
delete *(citer++);
pB.clear();
}
is it right?
Thank you
you’re missing a method to access your pointers, something like
and to delete a single pointer of the list: