From 341872c09593f41cbe27326d9462d4f7d7668ebd Mon Sep 17 00:00:00 2001 From: Asahel Date: Fri, 8 Mar 2024 09:49:58 -0800 Subject: implemented copy constructor and added files --- InclassExercise14/Contact.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/InclassExercise14/Contact.cpp b/InclassExercise14/Contact.cpp index fadde86..13f1183 100644 --- a/InclassExercise14/Contact.cpp +++ b/InclassExercise14/Contact.cpp @@ -9,6 +9,31 @@ class Contact { int zip{}; char* _email{}; +public: + + Contact(const Contact& other) { + firstName = new + char[strlen(other._firstName) + 1] + + _lastName = new + char[strlen(other._lastName) + 1]; + } + + contact& operator =(const Contact& other) { + if (this != &other) { + delete[] _firstName; + delete[]_lastName; + } + + return 0; + } + + Contact(Contact&& other) { + _firstName = other._firstName; + _lastName = other._lastName; + + other._firstName = nullptr; + other._lastName = nullptr; Contact() = default; Contact() { -- cgit v1.2.3