Lets say I have two classes.
the first class flowers has some functions for the flowers.
To tell if they are dead or alive.
the second class has flowers** ptr in private.
the second class needs to get a flower tell if its
dead or alive and if that flower has already been accessed.

Who is Participating?
MostlyWaterConnect With a Mentor Commented:
You have not stated what to do with this **Flower...
So, I guess you will use an "array of pointers".
is this what you want ?
class TFlower
 public :
  TFlower(void) //need a std c´tor for a vector
  { Alive = true; AlreadyAcessed=false; }

  bool isAlive(void) const
  { AlreadyAcessed=true; return Alive; }
  bool isDead(void) const { return ! isAlive(); }
  bool hasAlreadyBeenAcessed(void)const{return AlreadyAcessed;}
  //you need to define what "access" means :
  //  ->asking if dead or not == accessed
  //  ->killing a flower is an access
  //might add this (for the second meaning)
  void kill(void)
  { Alive=false;
    AlreadyAcessed=true; // ?? really ??
                                               //You would not really need "AlreadyAccessed" then
                         //because "Alive" would show if someone
                         //grabbed at the flower.
  //imagine this(probably what you wish to do)
  bool change(whatever parameters)//non-const
   //do your changes here, return true if params are chosen
   //within valid ranges

 private :
  bool Alive;
  bool AlreadyAcessed;

class TFlowerLst
 public :
  TFlowerPtrLst(//well, that depends what you will do with it.
                const int Size);

  killRandom(const int HowMany=1);
  int countAlive(void)const;//returns no of alive flowers
 private :
  TFlower **FlowerPtrs;
  int Size;
TFlowerLst::TFlowerLst(const int Size)
 FlowerPtrs = new (TFlower *)[Size];
 for(int i=0;i<Size;++i)
  FlowerPtrs[i] = new TFlower();//or whatever c´tor you will define
TFlowerLst::countAlive(void) const
 int RetVal=0;
 for(int i=0;i<Size;++i)
  if( FlowerPtrs[i] )
  { if( FlowerPtrs[i]->isAlive() )
    { ++RetVal; }
 return RetVal;
bool TFlowerLst::killRandom(const int HowMany/*=1*/)
 if( countAlive() < HowMany ) return false;//will hang otherwise
 //need to include stdlib.h for random()
 bool KilledOne=false;
 int  Index;
 for(int i=0;i<HowMany;++i)
  while( ! KilledOne )
  { Index = random(Size);
    if( FlowerPtrs[i]->isAlive() )
    { FlowerPtrs[i]->kill();
 return true;

Hope that helps
strmtrprAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.