-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrule_of_zero.cpp
executable file
·60 lines (50 loc) · 1.58 KB
/
rule_of_zero.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Rule of zero
Classes that have custom destructors, copy/move constructors or copy/move assignment operators
should deal exclusively with ownership. Other classes should not have custom destructors,
copy/move constructors or copy/move assignment operators.
*/
#include <string>
class rule_of_zero
{
std::string cppstring;
public:
rule_of_zero(const std::string& arg) : cppstring(arg) {}
};
/*
When a base class is intended for polymorphic use, its destructor may have to be declared public and virtual.
This blocks implicit moves (and deprecates implicit copies), and so the special member functions have to be
declared as defaulted
*/
class base_of_five_defaults
{
public:
base_of_five_defaults(const base_of_five_defaults&) = default;
base_of_five_defaults(base_of_five_defaults&&) = default;
base_of_five_defaults& operator=(const base_of_five_defaults&) = default;
base_of_five_defaults& operator=(base_of_five_defaults&&) = default;
virtual ~base_of_five_defaults() = default;
};
class foo
{
public:
/*
=0
C++ uses the special syntax = 0; to indicate pure virtual functions instead of adding a new keyword to the language
*/
void virtual pureVirtualFunction()=0;
/*
=default
It means that you want to use the compiler-generated version of that function, so you don't need to specify a body.
*/
~foo()=default;
/*
= delete
It means that the compiler will not generate those constructors for you. This is only allowed on copy constructor and assignment operator
*/
foo(const foo &t) = delete;
foo& operator = (const foo &t)= delete ;
};
int main()
{
}