C++ Compiler Generated Functions
What are generated functions:
Reference: Video
This are functions that the compiler adds when you don’t explicitly declare them(only if is required):
- Copy constructor
- Copy Assigment Operator
- Destructor
- Default constructor (only if there is not contructor declared)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Dog{};
// similar to
class Dog{
dog(const dog& rhs) {...} //Member by Member initialization
dog& operator=(const dog& rhs ) {...}; // Member by Member copying
dog() {...}; // 1- Call base class's default constructor
// 2- Call data member's default constructor.
~dog() {...};// 1- Call data class's destructor.
// 2- Call data member's destructor.
}
Additional Information:
- These are public and inline.
- They are generatedd only if they are needed
- A
default constructor
is a constructor that can work without any parameters.
This post is licensed under CC BY 4.0 by the author.