These are C++ tricks and tips I have found helpful. I call them C++ Pointers
and I hope you'll find them useful too.
C++ Pointersare licensed under the Creative Commons Attribution 4.0 International License. You should review the licence to determine your
You are free to,
provided that you follow the following licence terms,
C++ Pointers. Commercial use of my
C++ Pointersis allowed.
I have the following C++ Pointers
struct
s and STL ContainersAll the literature (both on-line and textbooks) I referenced to learn how to use STL containers only showed how to use them to hold primitives, such as integers and strings, and made no mention of how to handle objects or struct
s stored in a container.
This C++ Pointer
demonstrates how objects and struct
s can be stored in STL Maps and Vectors.
The standard practice / recommendation on how to handle a name collision between a class variable and a function is to append an underscore '_' to the end of one of the variable names.
This advice is troublesome when you are adding a mutator member function to an existing class and the variable is widely used throughout the class. Also the resulting code is untidy with some variable names having underscores and the remainder being without.
This C++ pointer
shows you how to have member function variables and class variables with same name.
All the literature I referenced to learn how to use STL containers only showed how to use them to hold primitives, (e.g. integers, strings, etc.), and made no mention of how to handle anything more complex.
This C++ Pointer
shows you how to work with a STL Vector or an STL Map stored in an STL Vector or an STL Map, which together form a simple means to handle application data. There are other STL containers, but once the use of these two containers is known the same techniques can be used for the others.
The example code also demonstates the technique of immediately storing a newly created object and then loading information into it as it is read in. This has the advantages that objects aren't created and then copied into the container, (especially beneficial for large objects), and there is no to worry about loading the current object when we reach the end of the data to load.
This C++ Pointer
shows you how to work with a Pointer contained in an STL Container, using an STL Vector or an STL Map. There are other STL containers, but once the use of these two containers is known the same techniques can be used for the others.
The example code also demonstates the technique of immediately storing a newly created object and then loading information into it as it is read in. This has the advantages that objects aren't created and then copied into the container, (especially beneficial for large objects), and there is no to worry about loading the current object when we reach the end of the data to load.