I'm in the process of writing a class that performs functions on a Distance
object. The object is created by entering details as "Distance a (5, km)" or
"Distance b (3, cm)" etc.
I wish to write a function that I can call to "as required by comparison
functions" to convert any value to a mm value so that when I'm comparing
Distance objects the values will all be the same.
The code I've come up with is below; however, it doesn't work correctly.
When I try and compile it the compiler advises it must return a value;
however, I simply want to replace the object that called to it with the new
values, ie Distance a (2, cm) to Distance a (20, mm) etc.
The constructor used in the class is as follows:
Distance :: Distance (int n, char m) : nu(n), me(m) {}
My function as follows:
int Distance::to_mm ()
{
if ( me == km)
{
nu = nu/1000000;
me = mm;
}
if (me == m)
{
nu = nu/1000;
me = mm;
}
if ( me == cm)
{
nu = nu/10;
me = m;
}
}
Thanks for any help
Comment