I admire your curiosity. Other reasons you declare pointers to objects; maybe one of these will satisy:
The declarations are there to tell the compiler to allocate memory for variables, structures, etc. When you declare an int, the compiler know you need four bytes of space on the stack. When you declare a string, how much memory should the compiler reserve for that? 100 bytes? 1000 bytes?
You don't know how large a string should be. So instead, you declare a pointer to a string, and let the string class itself decide how much memory to needs (it will ask for its own memory on the heap, as Joe said.) All we need on the stack is a pointer to the object.
Also, dealing with strings on the stack - without pointers - would be a hassle. Every time you added a string to an array, you'd have to copy the whole string. When you get it back out of the array, you'd have a different copy. This is no big deal with primitives like ints and floats because any "seven" is as good as another, but with more complicated objects it's easier to just pass around the object's address (that's what a pointer is) instead of the entire object.
__________________

Free Games!
|