-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
richelbilderbeek
committed
Feb 27, 2017
1 parent
c27d93e
commit 75544bd
Showing
13 changed files
with
340 additions
and
846 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,55 @@ | ||
# ([C++](Cpp.md)) [Big Four](CppBigFour.md) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
([C++](Cpp.md)) [Big Four](CppBigFour.md) | ||
=========================================== | ||
|
||
|
||
|
||
The [Big Four](CppBigFour.md) are the following four special | ||
In [C++98](Cpp98.md) the [Big Four](CppBigFour.md) are the following four special | ||
[class](CppClass.md) [member functions](CppMemberFunction.md) \[1\]: | ||
|
||
|
||
|
||
1. [Default constructor](CppDefaultConstructor.md) | ||
2. [Copy constructor](CppCopyConstructor.md) | ||
3. [Copy assignment operator](CppCopyAssignmentOperator.md) | ||
4. [Destructor](CppDestructor.md) | ||
|
||
In [C++11](Cpp11.md) there are the [Big Six](CppBigSix.md). | ||
|
||
## Example | ||
|
||
``` | ||
#include <iostream> | ||
|
||
///Gossip is a class that tells you what is happening to it | ||
struct Gossip | ||
{ | ||
Gossip() { std::cout << "Default constructor\n"; } | ||
Gossip(const Gossip&) { std::cout << "Copy constructor\n"; } | ||
~Gossip() { std::cout << "Destructor\n"; } | ||
Gossip& operator=(const Gossip&) { std::cout << "Copy assignment operator\n"; } | ||
|
||
|
||
|
||
}; | ||
Example | ||
------- | ||
|
||
|
||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ||
` #include <iostream> ///Gossip is a class that tells you what is happening to it struct Gossip { Gossip() { std::cout << "Default constructor\n"; } Gossip(const Gossip&) { std::cout << "Copy constructor\n"; } ~Gossip() { std::cout << "Destructor\n"; } Gossip& operator=(const Gossip&) { std::cout << "Copy assignment operator\n"; } }; int main() { { Gossip g; //Default constructor const Gossip h(g); //Copy constructor g = h; //Copy assignment operator //Destructor of g and h } }` | ||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ||
|
||
int main() | ||
{ | ||
{ | ||
Gossip g; //Default constructor | ||
const Gossip h(g); //Copy constructor | ||
g = h; //Copy assignment operator | ||
//Destructor of g and h | ||
} | ||
} | ||
``` | ||
|
||
Screen output: | ||
|
||
|
||
``` | ||
Default constructor | ||
Copy constructor | ||
Copy assignment operator | ||
Destructor | ||
Destructor | ||
``` | ||
---------------------------------------------------------------------------------------- | ||
` Default constructor Copy constructor Copy assignment operator Destructor Destructor` | ||
---------------------------------------------------------------------------------------- | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
[References](CppReferences.md) | ||
------------------------------- | ||
|
||
|
||
## [References](CppReferences.md) | ||
1. [Herb Sutter](CppHerbSutter.md), [Andrei | ||
Alexandrescu](CppAndreiAlexandrescu.md). C++ coding standards: 101 | ||
rules, guidelines, and best practices. 2005. ISBN: 0-32-111358-6. | ||
Introduction 'Class Design and Inheritance' | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# ([C++](Cpp.md)) [Big Six](CppBigSix.md) | ||
|
||
Since [C++11](Cpp11.md) the [Big Six](CppBigSix.md) are the following six special | ||
[class](CppClass.md) [member functions](CppMemberFunction.md): | ||
|
||
1. [Default constructor](CppDefaultConstructor.md) | ||
2. [Copy constructor](CppCopyConstructor.md) | ||
3. [Move constructor](CppMoveConstructor.md) | ||
4. [Copy assignment operator](CppCopyAssignmentOperator.md) | ||
5. [Move assignment operator](CppMoveAssignmentOperator.md) | ||
6. [Destructor](CppDestructor.md) | ||
|
||
In [C++98](Cpp98.md) there were only four, called [the Big Four](CppBigFour.md). | ||
|
||
## Example | ||
|
||
``` | ||
#include <iostream> | ||
///Gossip is a class that tells you what is happening to it | ||
struct Gossip | ||
{ | ||
Gossip() { std::cout << "Default constructor\n"; } | ||
Gossip(const Gossip&) { std::cout << "Copy constructor\n"; } | ||
Gossip(const Gossip&&) { std::cout << "Move constructor\n"; } | ||
~Gossip() { std::cout << "Destructor\n"; } | ||
Gossip& operator=(const Gossip&) { std::cout << "Copy assignment operator\n"; } | ||
Gossip& operator=(const Gossip&&) { std::cout << "Move assignment operator\n"; } | ||
}; | ||
int main() | ||
{ | ||
{ | ||
Gossip g; //Default constructor | ||
const Gossip h(g); //Copy constructor | ||
g = h; //Copy assignment operator | ||
//Destructor of g and h | ||
} | ||
} | ||
``` | ||
|
||
Screen output: | ||
|
||
``` | ||
Default constructor | ||
Copy constructor | ||
Copy assignment operator | ||
Destructor | ||
Destructor | ||
``` | ||
## Advice | ||
- Regarding the six operations above, implement as little as possible and declare as much as possible. Any operation not | ||
implemented shall be declared as default or delete [1] | ||
## [References](CppReferences.md) | ||
1. Gottschling, Peter. Discovering Modern C++: An Intensive Course for Scientists, Engineers, and Programmers. Addison-Wesley Professional, 2015. | ||
Chapter 2.5: 'Regarding the six operations above, implement as little as possible and declare as much as possible. Any operation not | ||
implemented shall be declared as default or delete' | ||
Oops, something went wrong.