Monday, July 27, 2009

Dynamically allocate memory to four instantces pointing to a?

I need some help figuring what I should do when I dynamically allocate memory to four instantces pointing to an animal class. After I allocate memory in the constructor, I must set it to "Lion", "Cat", "Dog", "Monkey". So far this is what I have written. Feedback would be great! The following code runs, however, I think I am not setting it correctly. I not quite sure?


//Animal.h


class Animal


{


private:


Animal *L;


Animal *C;


Animal *D;


Animal *M;





};


//Animal.cpp


Animal::Animal()


{


Animal *L = new Animal;


Animal *C = new Animal;


Animal *D = new Animal;


Animal *M = new Animal;


}

Dynamically allocate memory to four instantces pointing to a?
do you make a website on cs3?
Reply:Your animal class definition does not look right. Why does it have 4 animal pointers?


No comments:

Post a Comment