1 #include "DefaultMethods.h"
6 namespace DefaultMethods
13 // Default constructor (here we remove the default one).
20 C(C
&& other
) noexcept;
22 // A custom constructor.
25 // Copy-assignment operator.
26 C
& operator=(const C
& other
);
28 // Move-assignment operator.
29 C
& operator=(C
&& other
) noexcept;
38 cout
<< "Copy ctor, other.a = " << other
.a
<< endl
;
42 C::C(C
&& other
) noexcept
44 cout
<< "Move ctor, other.a = " << other
.a
<< endl
;
52 cout
<< "ctor, a = " << a
<< endl
;
55 C
& C::operator=(const C
& other
)
57 cout
<< "Copy assignment operator" << endl
;
62 C
& C::operator=(C
&& other
) noexcept
64 cout
<< "Move assignment operator" << endl
;
72 cout
<< "Destructor, a = " << this->a
<< endl
;
81 void DefaultMethods::tests()
83 // Use of universal initialization.
86 C c2
= move(c1
); // Force to treat 'c1' as a right-hand value.
89 cout
<< "c1.a = " << c1
.getA() << endl
;
90 cout
<< "c2.a = " << c2
.getA() << endl
;
91 cout
<< "c3.a = " << c3
.getA() << endl
;
92 cout
<< "c4.a = " << c4
.getA() << endl
;
94 cout
<< "--- copy some values" << endl
;
97 cout
<< "c1.a = " << c1
.getA() << endl
;
98 cout
<< "c2.a = " << c2
.getA() << endl
;