What do YOU use pointers for?

Started by
29 comments, last by Kaezin 20 years, 5 months ago
I only use pointers when I absolutely have to. Recursive data structures need them, graphics programming needs them, and so on..
Advertisement
Use pointers when you cannot use local (or in rare cases, global) variables for your purposes. It is as simple as that.

[edited by - CWizard on November 17, 2003 9:56:12 PM]
Thanks for the replies everyone, I''m just gonna stick with non-functions then. My g_Map was global in the earlier example.

If I wanted to initialize the map at a certain time why couldn''t I just call something like g_Map.Init() when I want it all to be set up properly?
Half the people you know are below average.Trogdor the Burninator
You are right, normally you don''t need pointers, or a variable is a pointer (like an object or interface) but can be used normally without really caring it''s a pointer.

You can make data structures that hold more than anything trivial into a class and have all functions that operate on that data methods.

You mention a pointer to your map class, but this is already implied if you have an object (a variable of type class xxx). So in your game class you just declare a variable of type cmap and create it (with new in C++, cmap.create in delphi) and then use it (and destroy it afterwards). So it''s a pointer but you never have to bother with *p or ^p.

The only times you need pointers is when you call functions that output a HRESULT and put output into memory pointed to by parameters.
Generally in containers, and I usually use smart pointers for that job. If I need a raw pointer, it''s allocated in the ctor and deleted in the dtor.

--
Dave Mikesell Software & Consulting
I use pointers where my experience tells me to do so. To use that tactic you need to practice C++ instead of letting people tell you how to theoreticly use C++.
[s]--------------------------------------------------------[/s]chromecode.com - software with source code
"I use pointers where my experience tells me to do so. To use that tactic you need to practice C++ instead of letting people tell you how to theoreticly use C++."

You, sir, are a moron. After all, these are forums. Forums are for questions. Am I asking them to write my map class for me? No. I''m asking so that I can know.

Go back into your cave, troll.
Half the people you know are below average.Trogdor the Burninator
quote:Original post by Kaezin
You, sir, are a moron.
Please, go easy on personal insults. He just expressed his opinion on the subject; no need to read in more to it than that.
quote:Original post by Kaezin
You, sir, are a moron. After all, these are forums. Forums are for questions. Am I asking them to write my map class for me? No. I''m asking so that I can know.

Go back into your cave, troll.

Um, not the best way to win fans over. You asked a question, he gave an answer, that is what forums are for right? I am sure he didn''t really mean that as an insult, the "For Beginners" forum is for people who aren''t that experienced in programming, so that is probably just an assumption on his part that you need more practice. Although I disagree slightly with his opinion, I would prefer to actually have some theoretical background before I attacked the practical applications, simply because it would lead to better programming practices. Pointers are one of the most difficult concepts to grasp in the C++ language, and it does take time and practice before someone can really get a hold of them for their own purposes. So look at what each of types do, and then use reason to choose the best one based on what your program requires.
quote:Original post by bastard2k5
Pointers are one of the most difficult concepts to grasp in the C++ language
Of the concepts that are particular to C++, surely pointers is one of the simplest?

This topic is closed to new replies.

Advertisement