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
orinterface inheritance
instead ofimplementation inheritance
Examples
Interface Inheritance
class Animal {
virtual void speak(); // (1)!
};
- Ensures that the
class
is explicitly anabstract class
, not possessing any implementations of the interfaces(functions
).
References
Read about cpp style guide