As the saga Continues

Started by
6 comments, last by clrscr 22 years, 1 month ago
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
-----------------------------When men speak of the future, the Gods laugh.An apology for the devil: it must be remembered that we have heard one side of the case. God has written all the books.Samuel Butler (1835 - 1902)
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)
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
or to have a dynamic array of pointers to pointers (say, for a list of c-style strings)...
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
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.
You need a lot of pointers to pointers for the DirectX API, but for my own routines i don''t use them.
int main(int argc, char** argv)
'ROIDRAGE!!! - I wanna work for the chinese communist regime!
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)
------------------------------Put THAT in your smoke and pipe it
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.

char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;}  /*** drpizza@battleaxe.net ***/

This topic is closed to new replies.

Advertisement