Skip to content

Commit a82730c

Browse files
committed
Update
1 parent cbcddde commit a82730c

2 files changed

Lines changed: 38 additions & 34 deletions

File tree

src/core/datatypes/class/CConstructors.cpp

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
// cppcheck-suppress-file [unusedVariable,unreadVariable]
12
#include <iostream>
23
using 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**
510
namespace InitializerList {
611
class 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
5761
namespace Default {
5862
class 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

8690
void 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
112116
namespace Delegate {
113117
class 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.
240244
namespace Move {
241245
class 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

307311
class 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");

src/core/datatypes/class/CDestructors.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include <iostream>
22
using namespace std;
33

4-
// *1. Basic Destructor
5-
// Generated if no destructor is declared
6-
// Calls destructors of members automatically
7-
// Does not free dynamically allocated memory unless you write it
4+
// ** 1. Basic Destructor**
5+
// - Generated if no destructor is declared
6+
// - Calls destructors of members automatically
7+
// - Does not free dynamically allocated memory unless you write it
88
namespace Basic {
99
class CDestructors {
1010
public:
@@ -25,7 +25,7 @@ void destructers() {
2525
}
2626
} // namespace Basic
2727

28-
// *2. Virtual Destructor
28+
// **2. Virtual Destructor**
2929
namespace Virtual {
3030
class CDestructorsBase // final => cannot inherit
3131
{
@@ -61,7 +61,7 @@ void destructers() {
6161

6262
class CDestructors : public IExample {
6363
public:
64-
std::string group() const override { return "core"; }
64+
std::string group() const override { return "core/class"; }
6565
std::string name() const override { return "CDestructors"; }
6666
std::string description() const override { return ""; }
6767
void execute() override {
@@ -70,4 +70,4 @@ class CDestructors : public IExample {
7070
}
7171
};
7272

73-
REGISTER_EXAMPLE(CDestructors, "core", "CDestructors");
73+
REGISTER_EXAMPLE(CDestructors, "core/class", "CDestructors");

0 commit comments

Comments
 (0)