I have a question:
Say I have originally these classes which I can't change (let's say because they're taken from a library which I'm using):
class Animal_
{
public:
Animal_();
int getIdA()
{
return idA;
};
string getNameA()
{
return nameA;
}
private:
string nameA;
int idA;
}
class Farm
{
public :
Farm()
{
sizeF=0;
}
Animal_* getAnimal_(int i)
{
return animals_[i];
}
void addAnimal_(Animal_* newAnimal)
{
animals_[sizeF]=newAnimal;
sizeF++;
}
private:
int sizeF;
Animal_* animals_[max];
}
But then I needed a class where I just add couple of fields so I did this:
class PetStore : public Farm
{
public :
PetStore()
{
idF=0;
};
private:
int idF;
string nameF;
}
However, I can't initialize my derived class. I mean I did this Inheritance so I can add animals
to my PetStore
but now since sizeF
is private how can I do that? I'm thinking maybe in the PetStore
default constructor I can call Farm()
... so any idea?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…