understanding class pointers

Hello all

I am trying to understand class pointer. I have a seen a lot of people use it on the forum. Hence, my questions are as follows below

1. What is the benefit of it?
2. Are there any good tutorials explaining in detail on it? because unfortunately when I go online to search for it I am not able to find good tutorials on it.
thanks in advance
a pointer is used to point.
that way you may establish relationships and comunication between objects.
1
2
3
4
5
6
7
8
9
10
class ford_pinto{
   person *driver;
   void crash(){
      driver->die();
   }
};

ford_pinto car;
car.driver = olychichi;
car.crash(); //guess you are dead 



> Are there any good tutorials explaining in detail on it?
perhaps I misread your question, ¿what are you trying to do?
Last edited on
Pointers are used primarily in two situations:

1) When you want to create an object dynamically.
1
2
3
4
  ford_pinto * car;
  car = new ford_pinto;
  // Do something with car
  delete car;  // Done with car.  Free the memory 

Pointers can get messy when you have multiple pointers pointing to the same object.

2) When you want to use polymorphism. In this case you have a base class and typically two or more derived classes. You should be able to find lots of articles on polymorphism.
http://www.cplusplus.com/doc/tutorial/polymorphism/

Topic archived. No new replies allowed.