From 387511e750a435b9857922bf290c2b5646ec6546 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 10 Oct 2023 19:04:43 +0200 Subject: [PATCH] better copy assignement default --- cpp/includes/Example.hpp | 4 ++-- cpp/src/Example.cpp | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cpp/includes/Example.hpp b/cpp/includes/Example.hpp index 84b425d..04917eb 100644 --- a/cpp/includes/Example.hpp +++ b/cpp/includes/Example.hpp @@ -7,8 +7,8 @@ struct Example { Example(); // constructor virtual ~Example(); // destructor - Example(const Example &); // copy constructor - Example &operator=(const Example &); // copy assignement + Example(const Example &); // copy constructor + const Example &operator=(const Example &); // copy assignement }; #endif diff --git a/cpp/src/Example.cpp b/cpp/src/Example.cpp index 13f7c03..1706b43 100644 --- a/cpp/src/Example.cpp +++ b/cpp/src/Example.cpp @@ -6,4 +6,10 @@ Example::~Example() {} Example::Example(const Example &) {} -Example &Example::operator=(const Example &src) { return *this; } +const Example &Example::operator=(const Example &src) { + if (this == &src) { + return *this; + } + + return *this; +}