posted 20 years ago
Not only can you use pointers, you can't not use pointers. When you say
Car car;
you have created a pointer that points to a Car object. When you then say
car=new Car();
you are telling the program what car points to. A car object is created somewhere off in ObjectLand, and the pointer car is set to point to it. Thus, when you say,
Car myCar=car;
the pointers are set to equal. There is ONLY one car, but both car and myCar point to it.
Thus, if I say,
myCar.breakForNoReason();
the car pointed to by myCar will break for no reason. Thus, car will also be broken, becuase the car pointed to is broken.
However, if you at some point say
myCar=new Car();
myCar is set to point to a brand new car, different from the one car points to. Then you can break myCar, and car will be uneffected,
dig?
[ December 12, 2004: Message edited by: Nick George ]
I've heard it takes forever to grow a woman from the ground