Style question, when to use pointers

V

Victor Bazarov

Karl said:
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).
 
A

Andrew Koenig

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,883
Members
47,414
Latest member
djangoframe

Latest Threads

Top