Skip to content

Commit

Permalink
Homework: clarify this, *this and operator=
Browse files Browse the repository at this point in the history
  • Loading branch information
cagix committed Jan 15, 2025
1 parent 3fc1d7d commit 38979bc
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions homework/src/cpp/class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class B {
B() { value = 0; }
B(int x) { value = x; }
B(B& rhs) { value = rhs.value; }
B& operator=(const B& rhs) {
this->value = rhs.value; // "this" sollte erkannt werden
return *this; // dito braucht man ein "*this" ...
B& operator=(B& rhs) { // Zuweisung ist der einzige notwendige Operator
value = rhs.value;
return *this; // "this" und "*this" sollten im Klassenkontext erkannt werden
}

int value;
Expand Down

0 comments on commit 38979bc

Please sign in to comment.