Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions concepts/classes/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The definition of a new `class` can be seen in the following example.
Notice the `;` after the definition.

```cpp
class Wizzard {
class Wizard {
public: // from here on all members are accessible publicly
int cast_spell() { // defines the public member function cast_spell
return damage;
Expand All @@ -43,7 +43,7 @@ Take a look at `damage` inside the `cast_spell` function.
You cannot read or change `private` members outside of the class:

```cpp
Wizzard silverhand{};
Wizard silverhand{};
// calling the `cast_spell` function is okay, it is public:
silverhand.cast_spell();
// => 5
Expand All @@ -64,12 +64,12 @@ A class can have several constructors.
This is useful if you do not always have a need to set all variables.

```cpp
class Wizzard {
class Wizard {
public:
Wizzard(std::string new_name) {
Wizard(std::string new_name) {
name = new_name;
}
Wizzard(std::string new_name, int new_damage) {
Wizard(std::string new_name, int new_damage) {
name = new_name;
damage = new_damage;
}
Expand All @@ -81,8 +81,8 @@ class Wizzard {
int damage{5};
};

Wizzard el{"Eleven"}; // deals 5 damage
Wizzard vecna{"Vecna", 50}; // deals 50 damage
Wizard el{"Eleven"}; // deals 5 damage
Wizard vecna{"Vecna", 50}; // deals 50 damage
```

Constructors are a big topic and have many nuances.
Expand All @@ -101,6 +101,6 @@ By default, everything in a `class` is `private`.
Structs, on the other hand, are `public` until defined otherwise.
Conventionally, the `struct` keyword is often used for **data-only structures**.
The `class` keyword is preferred for objects that need to ensure certain properties.
Such an invariant could be that the `damage` of your `Wizzard` `class` cannot turn negative.
Such an invariant could be that the `damage` of your `Wizard` `class` cannot turn negative.
The `damage` variable is private and any function that changes the damage would ensure the invariant is preserved.
~~~~
16 changes: 8 additions & 8 deletions concepts/classes/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The definition of a new `class` can be seen in the following example.
Notice the `;` after the definition.

```cpp
class Wizzard {
class Wizard {
public: // from here on all members are accessible publicly
int cast_spell() { // defines the public member function cast_spell
return damage;
Expand All @@ -42,7 +42,7 @@ Take a look at `damage` inside the `cast_spell` function.
You cannot read or change `private` members outside of the class:

```cpp
Wizzard silverhand{};
Wizard silverhand{};
// calling the `cast_spell` function is okay, it is public:
silverhand.cast_spell();
// => 5
Expand All @@ -63,12 +63,12 @@ A class can have several constructors.
This is useful if you do not always have a need to set all variables.

```cpp
class Wizzard {
class Wizard {
public:
Wizzard(std::string new_name) {
Wizard(std::string new_name) {
name = new_name;
}
Wizzard(std::string new_name, int new_damage) {
Wizard(std::string new_name, int new_damage) {
name = new_name;
damage = new_damage;
}
Expand All @@ -80,8 +80,8 @@ class Wizzard {
int damage{5};
};

Wizzard el{"Eleven"}; // deals 5 damage
Wizzard vecna{"Vecna", 50}; // deals 50 damage
Wizard el{"Eleven"}; // deals 5 damage
Wizard vecna{"Vecna", 50}; // deals 50 damage
```

Constructors are a big topic and have many nuances.
Expand All @@ -100,6 +100,6 @@ By default, everything in a `class` is `private`.
Structs, on the other hand, are `public` until defined otherwise.
Conventionally, the `struct` keyword is often used for **data-only structures**.
The `class` keyword is preferred for objects that need to ensure certain properties.
Such an invariant could be that the `damage` of your `Wizzard` `class` cannot turn negative.
Such an invariant could be that the `damage` of your `Wizard` `class` cannot turn negative.
The `damage` variable is private and any function that changes the damage would ensure the invariant is preserved.
~~~~