jeudi 21 juillet 2016

C++ New up std::vector of pointers

I have an Animal class. The DiffClass, has pointers to the Animal class. I am trying to work out how to properly use std::vector instead of new as it means I don't have to delete the memory myself. I don't understand why the vector does not recognise the function in the Animal class. Any clue?

class Animal
{
 void display(); //displays one animal
}

class DiffClass
{
 public:
    void someFunctionToSetUpVector()
    {
     AnimalPointer = new std::vector<Animal>;
      for ( int i = 0; i <AnimalPointer.size(); i++)
      {
        AnimalPointer[i].display(); // does not work, can't find function
      }
    }
 private:
    std::vector<Animal>* AnimalPointer = 0;
}

Aucun commentaire:

Enregistrer un commentaire