Overloaded Member Function

I am getting the following error:
error C2511: 'double Distance::MtoE(double) const' : overloaded member function not found in 'Distance'

I am new at this, and not sure what I need to do to correct the error message... Here is a snippet of my 'Distance' Class:
public:
      //constructors -
      Distance ();  //default constructor
      Distance (long millimeter);
      Distance (long meter, long centimeter, long millimeter);
      Distance (int feet, int inches);
      Distance (double miles);

      //Access Functions
      double GetDistance () const;  // distance storing converted to mm
      void SetDistance (double mm); // "set the stored distance accordingly"?

      //Conversion functions
      double MtoE () const;

Then here is where the error is pointing me to....
double Distance::MtoE (double value) const {
       double value = 0;
      // converting given value to millimeters
      (value * MTF) / 1000; // MTF is defined in the header.
}


Any advice / explanation would be very much appreciated.
gndcdospsAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Infinity08Connect With a Mentor Commented:
       double MtoE () const;

does not correspond to :

        double Distance::MtoE (double value) const

They need to be the same ... do you need a double argument or not ? If so, then put this inside the class :

        double MtoE (double value) const;

if not, then modify the implementation like this :

        double Distance::MtoE () const {
            // the code ...
        }
0
 
ravenplCommented:
from class prototype
Distance (double miles);
from implementation
double Distance::MtoE (double value) const

either add const in class declaration, or strip the const from method definition (implementation)
0
 
ravenplCommented:
I'm sorry - ignore my comment - lloks like I'm too tired now.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
evilrixConnect With a Mentor Senior Software Engineer (Avast)Commented:
double Distance::MtoE (double value) const {
       double value = 0;
      // converting given value to millimeters
      (value * MTF) / 1000; // MTF is defined in the header.
}

This function is prototyped to return a double... it returns nothing. This will also cause you a compiler error. Also, it takes value as a parameter and then sets it to 0 and then uses it in a multiplication (anything multiplied by 0 is 0!) and then divides 0 by 1000 -- also 0!

You seem to have a few inconsistencies to sort out here :)
0
 
evilrixSenior Software Engineer (Avast)Commented:
>> Also, it takes value as a parameter and then sets it to 0
Strike that, I'll re-state: it takes value as a parameter and also declares a local variable called value, which is set to 0.
0
 
ravenplCommented:
Declaring local variable with same name as parameter shadows the param - the parameter is inaccessible then. Usually compiler casts a warning.
But I guess Infinity08 said all required here. There's inconsistency between declaration and definition...
0
 
Infinity08Commented:
>> But I guess Infinity08 said all required here.

All required to solve the compiler error mentioned in the question ;)

But evilrix is right that there are further problems ... We can fix them one at a time though ... It's just waiting for gndcdosps to get back to us now heh :)
0
 
gndcdospsAuthor Commented:
Sorry for the delayed response... Can you give me a little bit to look over your comments.  I am working from home today, and have to take care of a few things before I can look at this, again.  It may be a couple of hours....
0
 
Infinity08Commented:
No problem ... Take your time. And remember : in case there are further problems, feel free to ask about them. In that case, it would also be good to post a bit more code ...
0
 
evilrixSenior Software Engineer (Avast)Commented:
>> Declaring local variable with same name as parameter shadows the param - the parameter is inaccessible then. Usually compiler casts a warning
It'll given a error, since it's a redefinition of a variable within the same scope.

>> There's inconsistency between declaration and definition...
Yes there is but there are also other issues that will cause problems when this is resolved.
0
 
gndcdospsAuthor Commented:
I am sorry I did not get back to everyone sooner.  I am back to trying to figure this out, but believe I will be doing another post.  

Thanks as always for you time, help, and expertise!
0
All Courses

From novice to tech pro — start learning today.