From f5524b020c081cf8ba77dc566536c67701feca7a Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Tue, 30 Jun 2020 12:57:01 +0200 Subject: [PATCH] Ex4.1 feedback: Copy constructors of dependency objects were not called when copying Telephone --- ex4.1/Telephone.hh | 18 +++++++++++++++--- ex4.1/main.cpp | 4 ++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ex4.1/Telephone.hh b/ex4.1/Telephone.hh index 371d826..e2d3da0 100644 --- a/ex4.1/Telephone.hh +++ b/ex4.1/Telephone.hh @@ -9,9 +9,21 @@ class Telephone { public: - Telephone() { std::cout << "Telephone Constructor " << this << std::endl ; } - Telephone(const Telephone& t ) { std::cout << "Telephone Copy Constructor " << this << std::endl ; } - ~Telephone() { std::cout << "Telephone Destructor " << this << std::endl ; } + Telephone() { + std::cout << "Telephone Constructor " << this << std::endl; + } + Telephone(const Telephone& t ) { + std::cout << "Telephone Copy Constructor " << this << std::endl; + + // Copy the data members + Cable cable = t.cable; + Housing housing = t.housing; + Dialer dialer = t.dialer; + Handset handset = t.handset; + } + ~Telephone() { + std::cout << "Telephone Destructor " << this << std::endl; + } private: diff --git a/ex4.1/main.cpp b/ex4.1/main.cpp index 1d527dc..263bc75 100644 --- a/ex4.1/main.cpp +++ b/ex4.1/main.cpp @@ -3,5 +3,9 @@ int main(){ Telephone t; + std::cout << std::endl; + std::cout << "Cloning the Telephone object" << std::endl; + std::cout << std::endl; + Telephone t2 = t; }