From 38979bcf88ec102966e66e4792a293dbe3c04e5f Mon Sep 17 00:00:00 2001 From: Carsten Gips Date: Wed, 15 Jan 2025 09:00:39 +0100 Subject: [PATCH] Homework: clarify this, *this and operator= --- homework/src/cpp/class.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homework/src/cpp/class.cpp b/homework/src/cpp/class.cpp index d1496230..d10c886e 100644 --- a/homework/src/cpp/class.cpp +++ b/homework/src/cpp/class.cpp @@ -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;