 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Karl Guest
|
Posted: Tue Dec 30, 2003 5:54 pm Post subject: Style question, when to use pointers |
|
|
Generally when do you use pointers rather than stack variables?
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Tue Dec 30, 2003 6:04 pm Post subject: Re: Style question, when to use pointers |
|
|
"Karl" <no@emailprovided> wrote...
| Quote: |
Generally when do you use pointers rather than stack variables?
|
When I need the object to survive across functions (especially
upon return), with minimal overhead. When I need polymorphic
behaviour (although in some situations references are OK).
|
|
| Back to top |
|
 |
Andrew Koenig Guest
|
Posted: Tue Dec 30, 2003 6:29 pm Post subject: Re: Style question, when to use pointers |
|
|
| Quote: | Generally when do you use pointers rather than stack variables?
|
If you can use
an iterator referring to an element of a standard-library container, or
a local variable (what you are referring to as a stack variable), or
a reference,
then you shouldn't use a pointer unless you can clearly articulate a reason
why a pointer is superior to any of these alternatives.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|