I'm still a learner so I'm also interested in what pointers are primarily used for.
But I do know one use of pointers in C++ is taking advantage of inheritance and polymorphism. Those 2 features are useful in some cases (I took advantage of them in my Uno playing program by declaring the classes Human and AI as inheriting from Players, and have the Players morph into Human or AI)
Also, Qt programs and books usually encourage you to use pointers and "new" them instead of declaring the objects directly. Still dunno why
I wanted to get back to this conversation with an example of what confuses me about pointer use.
See the code examples on this page:
http://zetcode.com/gui/qt4/layoutmanagement/
Notice that in verticalbox.cpp all the widgets are created as pointers using "new".
But in main.cpp, "window" is just created directly.
Why is it different?
Bookmarks