944,066 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2163
  • C++ RSS
Oct 26th, 2007
0

Dynamic Allocating memory

Expand Post »
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;
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hellokitty88 is offline Offline
6 posts
since Dec 2006
Oct 26th, 2007
0

Re: Dynamic Allocating memory

It is not proper C++, have animal as a base class and derive dog, cat, man from the base class animal
Reputation Points: 769
Solved Threads: 128
Banned
ithelp is offline Offline
1,910 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: homework help
Next Thread in C++ Forum Timeline: problem to convert string to integer using Dev-c++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC