-
Pointers
Hi everyone.
I'm a bit confused on pointers, when i was reading Introduction to game programming with DirectX 9.0 i stumbled on a lot of pointers, i was just wondering, what are they really for, what could i use them for in every-day programming situations, i thought i could ignore it but i think that i really need to know more about them before i move on.
Thanks for all of your help in advance.
-
-
-
I have read the tutorial, and 3 books, i know how to use pointers, i just don't know in what situation to use them in.
-
Well that's a different thing, isn't it? What you say is what we think you mean. People seem to never understand that we can't read minds.
Anyway, you use them where you think they apply. There are recommendations, but there isn't some rule that says you can use them only under certain conditions. I recommend you do what you can with what you know, until you reach a problem where using pointers can help you get through.
It might be speed, or efficiency in algorithms, or etc. etc...
Why don't you just use google to search for "C++ When should I use pointers" or something similar, you'll find a lot of information if you try.
-
In C++, it's best to avoid using naked pointers whenever possible. References are preferred for arguments to functions (see here) and standard containers are preferred to dynamically allocated arrays.
Sometimes, you might find you need to use dynamic allocation so that you have control over the lifetime of an object or for polymorphism, in which case you may need to use pointers. But even then, you should consider if a smart pointer (see boost libraries or std::auto_ptr, for example) can be used instead.
-
>> I have read the tutorial, and 3 books, i know how to use pointers, i just don't know in what situation to use them in.
The links I posted include a huge discussion of exactly that question.