1+ // cppcheck-suppress-file [unusedVariable,unreadVariable]
12#include < iostream>
23using namespace std ;
34
4- // *1. Members initializer list constructor
5+ // NOTE: We can throw an exception in a constructor to signal an error,
6+ // and then catch that error using a standard try-catch block
7+ // where the object is being instantiated.
8+
9+ // **1. Members initializer list constructor**
510namespace InitializerList {
611class CConstructors {
712 private:
@@ -49,11 +54,10 @@ void constructers() {
4954}
5055} // namespace InitializerList
5156
52- // *2. Default constructor:
53- // It is a constructor that accepts no arguments.
54- // Generated if no constructors are declared
55- // Initializes members: basic types uninitialized, class types call their
56- // default constructor
57+ // **2. Default constructor**
58+ // - It is a constructor that accepts no arguments.
59+ // - Generated if no constructors are declared
60+ // - Initializes members: basic types uninitialized, class types call their default constructor
5761namespace Default {
5862class UConstructors {
5963 public:
@@ -71,7 +75,7 @@ class EConstructors {
7175 public:
7276 // we already create the constructor ourselves
7377 // EConstructors(int a)
74- explicit EConstructors (float a) // explicit -> [[maybe_unused]]
78+ explicit EConstructors (float a) // explicit ->
7579 // EConstructors obj2 = 1; [ERROR]
7680
7781 {
@@ -85,29 +89,29 @@ class EConstructors {
8589
8690void constructers () {
8791 cout << " \n --- Default Constructer Examples ---\n " ;
88- [[maybe_unused]] UConstructors obj1;
89- // [[maybe_unused]] UConstructors obj2(); // wrong, this is function declare
92+ UConstructors obj1;
93+ // UConstructors obj2(); // wrong, this is function declare
9094 // FYI:
9195 // void outer()
9296 // {
9397 // void helper();
9498 // helper(); // defined later in the same file
9599 // }
96100
97- [[maybe_unused]] UConstructors obj3{};
101+ UConstructors obj3{};
98102
99- [[maybe_unused]] IConstructors obj4;
100- [[maybe_unused]] IConstructors obj6{};
103+ IConstructors obj4;
104+ IConstructors obj6{};
101105
102- [[maybe_unused]] EConstructors obj7;
103- [[maybe_unused]] EConstructors obj9{};
106+ EConstructors obj7;
107+ EConstructors obj9{};
104108
105- [[maybe_unused]] EConstructors obj10 (1.2 );
106- [[maybe_unused]] EConstructors obj11{2 };
109+ EConstructors obj10 (1.2 );
110+ EConstructors obj11{2 };
107111}
108112} // namespace Default
109113
110- // *3. Delegate constructor: allow to delegate initialization to another
114+ // ** 3. Delegate constructor: allow to delegate initialization to another**
111115// constructor Never generated automatically
112116namespace Delegate {
113117class CConstructor {
@@ -138,9 +142,9 @@ void constructors() {
138142}
139143} // namespace Delegate
140144
141- // *4. Copy constructor: initialize an copy object with an existing object
142- // Generated if no copy/move constructor or `destructor` is declared
143- // Performs memberwise (shallow) copy
145+ // ** 4. Copy constructor: initialize an copy object with an existing object**
146+ // - Generated if no copy/move constructor or `destructor` is declared
147+ // - Performs memberwise (shallow) copy
144148// * Copy constructor
145149// Object obj1 = obj2
146150// Object obj1(obj2)
@@ -232,11 +236,11 @@ void constructors() {
232236}
233237} // namespace Copy
234238
235- // *4. Move Constructor:
236- // Move constructor and move assignment transfer resource ownership
237- // from one object to another. This is usually cheaper than copying.
238- // A move constructor is implicitly generated only if no user-declared
239- // copy constructor, move constructor, or destructor exists.
239+ // ** 4. Move Constructor**
240+ // - Move constructor and move assignment transfer resource ownership
241+ // - from one object to another. This is usually cheaper than copying.
242+ // - A move constructor is implicitly generated only if no user-declared
243+ // copy constructor, move constructor, or destructor exists.
240244namespace Move {
241245class Model // C++ will create a public implicit copy constructor for us if we
242246 // do not provide a one.
@@ -306,7 +310,7 @@ void constructers() {
306310
307311class CConstructors : public IExample {
308312 public:
309- std::string group () const override { return " core" ; }
313+ std::string group () const override { return " core/class " ; }
310314 std::string name () const override { return " CConstructors" ; }
311315 std::string description () const override { return " " ; }
312316 void execute () override {
@@ -318,4 +322,4 @@ class CConstructors : public IExample {
318322 }
319323};
320324
321- REGISTER_EXAMPLE (CConstructors, " core" , " CConstructors" );
325+ REGISTER_EXAMPLE (CConstructors, " core/class " , " CConstructors" );
0 commit comments