Ex4.1 feedback: Copy constructors of dependency objects were not called when copying Telephone
This commit is contained in:
		
							parent
							
								
									95ddbf5bde
								
							
						
					
					
						commit
						f5524b020c
					
				
					 2 changed files with 19 additions and 3 deletions
				
			
		| 
						 | 
					@ -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:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue