We use CMake to build C++ code.
- Use one of the compiler LLvm - clang, 'Gnu Compiler Collection' gcc or 'Gnu C Compiler' g++, and enable warning flags while compiling your code
It is better to use shared pointers to avoid any possible memory leaks.
Follow the following simple ruls.
For each Class define a type for the shared_ptr like the following
#include <memory>
class Auto;
typedef std::shared_ptr<Auto> AutoPtr;
To instatiate an object of the specifc class
auto myAuto = std::make_shared <Auto>();
When the object is out of reference then it will be removed from memory. It is done by reference counting.
There is no need to use raw points.
You can always use the shared_ptr that you defined like "AutoPtr".
If there is a real need to use c++ raw pointers you can access it as well.
Each component should be in a separate folder and separate namespace.
Do not include the headers with the hard path on the project structure because you may want to move the header files later. Header files should be included without directory structure. See the project. We can include the headers from each folder and each headers directory in the CMakeList file.
- Check Memory Leaks using valgrind
valgrind -v --leak-check=full --tool=memcheck <your_app> <your_apps_params>
For this project
valgrind -v --leak-check=full --tool=memcheck ./Example-1
-
we recommend to use the google C++ style guide
-
we recommend to use the Cppcheck to check the style of your code.