Can anyone check my logic here. I just want to know whether I'm understanding the logic behind this code.
When you pass your Car object to a method declared like this:
void cost(Car f) const throw();
The method cannot modify the Car object because the method is marked by const. Also a copy of the object is passed to the parameter of the cost function.
When you pass your Car object to a method declared like this:
void cost(const Car& f) const throw();
The method cannot modify the Car object because the method is marked by const. This time, a copy is not passed to the parameter of the cost function. Instead, the actual Car object is passed to the parameter list and is marked by const, which means that the cost function cannot modify this Car reference object.
When you pass your Car object to a method declared like this:
void cost(Car f) const throw();
The method cannot modify the Car object because the method is marked by const. Also a copy of the object is passed to the parameter of the cost function.
When you pass your Car object to a method declared like this:
void cost(const Car& f) const throw();
The method cannot modify the Car object because the method is marked by const. This time, a copy is not passed to the parameter of the cost function. Instead, the actual Car object is passed to the parameter list and is marked by const, which means that the cost function cannot modify this Car reference object.