Advertisement

02.24.2007 at 02:30AM PST, ID: 22410793
[x]
Attachment Details

C++ - Pointer to Vector of Pointers

Asked by XPUSR in C++ Programming Language

Tags: vector, pointer

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(vector<FruitSegments*> *& vecFruitSegments)
   }
     // Sub Class
   class FruitSegments
   {
      public:
       
      private:
      // Private member vars
   }

 // Private member vars
  vector<Fruit*> vecFruits;
  vector<Fruit*> vecFruitSegments;
}


The implementations:
Basket::Fruit::Fruit(vector<FruitSegments*> & vecFruitSegments)
{
  AddFruitSegmentsToVector(vecFruitSegements);
}

Basket::FruitSegments::AddFruitSegmentsToVector(vector<FruitSegments*> *& 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(AddFruitSegmentsToVector)? 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
[+][-]02.24.2007 at 02:42AM PST, ID: 18601563

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C++ Programming Language
Tags: vector, pointer
Sign Up Now!
Solution Provided By: MacroLand
Participating Experts: 4
Solution Grade: A
 
 
[+][-]02.24.2007 at 03:02AM PST, ID: 18601593

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.24.2007 at 08:25AM PST, ID: 18602199

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.02.2007 at 05:05PM PDT, ID: 19202231

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]04.23.2008 at 07:14PM PDT, ID: 21427276

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32