We help IT Professionals succeed at work.

Overloaded Member Function

gndcdosps
gndcdosps asked
on
Medium Priority
2,237 Views
Last Modified: 2013-12-14
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.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2009
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 ...
        }
Top Expert 2005

Commented:
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)
Top Expert 2005

Commented:
I'm sorry - ignore my comment - lloks like I'm too tired now.
evilrixSenior Software Engineer (Avast)
CERTIFIED EXPERT
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 :)
evilrixSenior Software Engineer (Avast)
CERTIFIED EXPERT

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.
Top Expert 2005

Commented:
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...
CERTIFIED EXPERT
Top Expert 2009

Commented:
>> 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 :)

Author

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....
CERTIFIED EXPERT
Top Expert 2009

Commented:
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 ...
evilrixSenior Software Engineer (Avast)
CERTIFIED EXPERT

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.

Author

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!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.