Dynamic Allocating memory

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2006
Posts: 6
Reputation: hellokitty88 is an unknown quantity at this point 
Solved Threads: 0
hellokitty88 hellokitty88 is offline Offline
Newbie Poster

Dynamic Allocating memory

 
0
  #1
Oct 26th, 2007
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;
}
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,861
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 120
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: Dynamic Allocating memory

 
0
  #2
Oct 26th, 2007
It is not proper C++, have animal as a base class and derive dog, cat, man from the base class animal
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1642 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC