Giter VIP home page Giter VIP logo

cppprojecttemplate's Introduction

CPP Project Template

Build Status

Build and Run

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

Use Share Pointers

It is better to use shared pointers to avoid any possible memory leaks.

Follow the following simple ruls.

1. A type for the shared_ptr

For each Class define a type for the shared_ptr like the following

#include <memory>

class Auto;
typedef std::shared_ptr<Auto> AutoPtr;

2. No use of new() operator, no use of delete()

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.

3. No C++ raw pointers

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.

4. Keep the project structure.

Each component should be in a separate folder and separate namespace.

5. Include headers without hardcoded path like - Not like #include "../../../Blabla.h"

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

valgrind -v --leak-check=full --tool=memcheck <your_app> <your_apps_params>

For this project

valgrind -v --leak-check=full --tool=memcheck ./Example-1

Code Sytle

cppprojecttemplate's People

Contributors

kiat avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.