Hi Experts,
I have the following class and sub-classes:
class Basket
{
public:
private:
// Sub Class
class Fruit
{
public:
// Constructor
Fruit(vector<FruitSegments
*> & vecFruitSegments)
private:
AddFruitSegmentsToVector(v
ector<Frui
tSegments*
> *& vecFruitSegments)
}
// Sub Class
class FruitSegments
{
public:
private:
// Private member vars
}
// Private member vars
vector<Fruit*> vecFruits;
vector<Fruit*> vecFruitSegments;
}
The implementations:
Basket::Fruit::Fruit(vecto
r<FruitSeg
ments*> & vecFruitSegments)
{
AddFruitSegmentsToVector(v
ecFruitSeg
ements);
}
Basket::FruitSegments::Add
FruitSegme
ntsToVecto
r(vector<F
ruitSegmen
ts*> *& vecFruitSegments)
{
FruitSegment *fruitseg = new FruitSegment();
vecFruitSegments.push_back
(fruitseg)
;
}
My question is concerned with the *& operator? Is this the correct method to add a new FruitSegment to a vector of pointers which has been passed to a method(Fruit) to another method(AddFruitSegmentsToV
ector)? I have tried this and it works for the first call to the object however the pointers to the FruitSegement objects don't seen to get deleted from memory???
Start Free Trial