Home Segments Index Top Previous Next

678: Practice

You have learned that the use of railroad_car objects as call-by-value parameters can lead to excessive reclamation bugs. The best way to avoid such bugs is to use call-by-reference parameters instead. Then, you ensure that you do not inadvertently use a call-by-value parameter by defining a private copy constructor.

Another way to avoid excessive reclamation is to rewrite the railroad_car destructor. Now it reads as follows:

virtual ~railroad_car ( ) {delete [ ] serial_number;} 

You can change it to

virtual ~railroad_car ( ) { } 

What is wrong with this alternative?