C++ Question

Started by
9 comments, last by Brerick 21 years, 2 months ago
I use pointers continuously for dynamic allocation. Suppose I want an array of integers but I have no idea how many I'll actually need until Run Time. You can't do much without pointers there.

Pointers are also great when you get into class hierarchies. A pointer to a base class can point to an object of any class derived from that base class. Then, when you don't know the actual class type until Run Time, you can adapt to the situation at hand. Let's say we're going to have a pointer to a pet in a game (stupid example - bear with me).

class Animal;class Dog : Public Animal;class Cat : Public Animal;Animal *pet  


Now you're pointer *pet can point to a Dog or a Cat object. Nice.

I love pointers!!

-Kirk



[edited by - KirkD on January 30, 2003 2:05:10 PM]

This topic is closed to new replies.

Advertisement