1
0
Fork 0

Ex4.1 feedback: Copy constructors of dependency objects were not called when copying Telephone

This commit is contained in:
Eric Teunis de Boone 2020-06-30 12:57:01 +02:00
parent 95ddbf5bde
commit f5524b020c
2 changed files with 19 additions and 3 deletions

View file

@ -9,9 +9,21 @@
class Telephone { class Telephone {
public: public:
Telephone() { std::cout << "Telephone Constructor " << this << std::endl ; } Telephone() {
Telephone(const Telephone& t ) { std::cout << "Telephone Copy Constructor " << this << std::endl ; } std::cout << "Telephone Constructor " << this << std::endl;
~Telephone() { std::cout << "Telephone Destructor " << 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: private:

View file

@ -3,5 +3,9 @@
int main(){ int main(){
Telephone t; Telephone t;
std::cout << std::endl;
std::cout << "Cloning the Telephone object" << std::endl;
std::cout << std::endl;
Telephone t2 = t; Telephone t2 = t;
} }