Simple inheritance question
if I had the code Mammal *pDog = new Dog;, Mammal being a base class and dog being a derrived one, could pDog be a pointer to any derrived class of Mammal and still work the same as if I did something like Dog * pDog = new Dog?
Thanks.
No. only dogs (or classes derived from dogs) work as dogs. Lets say you had another class Cat, derived from Mammal. Then the cat could not do dog stuff. The only thing it has in common with dogs is the stuff from Mammel.
Jacob Marner, M.Sc.
Console Programmer, Deadline Games
Jacob Marner, M.Sc.
Console Programmer, Deadline Games
Jacob Marner, M.Sc.Console Programmer, Deadline Games
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement