Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

clrscr

As the saga Continues

This topic is 5994 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

As my never ender sage to learn C++ continues I must ask, why would you ever need a pointer to a pointer? "The most likely way for the world to be destroyed, most experts agree, is by accident. That''s where we come in; we''re computer professionals. We cause accidents." -Nathaniel Borenstein

Share this post


Link to post
Share on other sites
Advertisement
To pass the pointer to a function, and have the function change the address the pointer is pointing to.

The world holds two classes of men -- intelligent men without religion, and religious men without intelligence. Abu''l-Ala-Al-Ma''arri (973-1057; Syrian poet)

Share this post


Link to post
Share on other sites
or to have a dynamic array of pointers to pointers (say, for a list of c-style strings)...

Share this post


Link to post
Share on other sites
The simple answer is "you hardly ever need a pointer to a pointer". I can''t remember the last time I needed this in C++. If you can''t think of why you would need one, then you probably don''t need one. Most uses of pointers in C++ should be replaced with strings, vectors, smart pointers, handle classes, etc.

Share this post


Link to post
Share on other sites
You need a lot of pointers to pointers for the DirectX API, but for my own routines i don''t use them.

Share this post


Link to post
Share on other sites
You really won''t need pointers until later in your "saga" when you learn a graphics/sound/input API. Right now, just read as much about them as you can so you understand them as well as possible. Once you start to need them, read about them again, and you''ll find a use for them if need be.

As of now, I''ve coded a bunch of small games and I haven''t used any pointers, other than ones that were needed to use my API.

Good luck!

------------------------------
Simple DirectMedia Layer:

Main Site - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net''s Tutorials - (Here)

OpenGL:

Main Site - (www.opengl.org)
NeHe Tutorials - (nehe.gamedev.net)
Online Books - (Red Book) (Blue Book)

Share this post


Link to post
Share on other sites
quote:
Original post by SabreMan
The simple answer is "you hardly ever need a pointer to a pointer". I can''t remember the last time I needed this in C++. If you can''t think of why you would need one, then you probably don''t need one. Most uses of pointers in C++ should be replaced with strings, vectors, smart pointers, handle classes, etc.

I''m genuinely surprised at this claim. Pointers to pointers are used extensively in many many APIs. Generally, containers should be used to store pointers to objects instead of objects themselves (because copying pointers is faster than copy c-tors).

Whilst you might not create the pointers to pointers yourself, that doesn''t obviate their need.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!