PImpl Idiom
- The PImpl Idiom (Pointer to IMPLementation) is a technique used for separating implementation from the interface. It minimizes header exposure and helps programmers to reduce build dependencies by moving the private data members in a separate class and accessing them through an opaque pointer.
- Advantages: Binary Compatibility, Less compilation time (Only the implementation file needs to be rebuild), Data Hiding
- Disadvantages: More memory allocation than with the default structure, More complex maintenance, Inheritance problem
RAII
- Resource Acquisition is Initialization binds the life cycle of a resource that must be acquired before use (allocated heap memory, thread of execution, open socket, open file, locked mutex, disk space, database connection and etc.) to the lifetime of an object.
- It also guarantees that all resources are released when the lifetime of their controlling object ends, in reverse order of acquisition.
const
- const int * abc: Declares that the abc is a variable pointer to a constant integer.
- int const * abc: Also declares that the abc is a variable pointer to a constant integer.
- int * const abc: A const pointer to a variable integer. Useful for storage that can be changed in value but not moved in memory.
- int const * const abc: A const pointer to a const integer.
Parameter passing
- void Subroutine(big_structure_type &Parameter);
- Using & maybe because it is going to alter the variable passed to it or might just be to save copying time and there is no way to tell which it is.
- In this case, we could use the following signature for the second situation: void Subroutine(big_structure_type const &Parameter).
Object Oriented Programming
1
2
3class Class2{
void Method1() const;
int MemberVariable1;}- Which will ban Method1 in Class2 from being anything which can attempt to alter any member variables in the object.
- Method1 could be called without having an object of Class2
constexpr
- The constexpr specifier declares that it is possible to evaluate the value of the function or variable at compile time. Such variables and functions can then be used where only compile time constant expressions are allowed.