Skip to content

Google

C++ Style Guide

  • Use 2 spaces, not tabs, escaping the dependency over engineers' machine configuration, affecting how code looks to each individual.
  • Use auto to only make the code safer or clearer, otherwise use explicit types.
  • Don't use pointers, if you want to use them then use std::unique_ptr
  • Minimize the usage of exceptions
  • Use composition or interface inheritance instead of implementation inheritance

Examples

Interface Inheritance

class Animal {
    virtual void speak(); // (1)!
};
  1. Ensures that the class is explicitly an abstract class, not possessing any implementations of the interfaces(functions).

References

Read about cpp style guide