PDA

View Full Version : Confusing errors in simple overload program...help?


kevin
24 Jun 2003, 8:05pm
I am having a bit of trouble with this C++ program and cursed ANSI C++ (oh why did I want to stray from thee, faithful microsoft? lol). I cant figure out why the hell I am getting this error (and neither can L0ki, which majorly surprises me) in my program...Try to compile it for yourself to see the error, there are way to many to list here and they are all way to vague...
Heres the code, its an attempt at screwing with overloads:

// overdist.cpp
// demonstrates overloading
#include <iostream>
using namespace std;

struct distance
{
int feet;
float inches;
};

void engldisp (distance);
void engldisp (float);

int main()
{
distance d1; //distance of type distance
float d2; //distance of float
//get d1 from user
cout<<"Enter feet: "; cin>>d1.feet;
cout<<"Enter inches: "; cin>>d1.inches;
//get d2 from user
cout<<"Enter entire distance 2 in inches: "; cin>>d2;
cout<<"\nd1 = ";
engldisp(d1);
cout<<"\nd2 = ";
engldisp(d2);
return 0;
}
void engldisp(distance dd) //for type distance
{
cout<<dd.feet<<"\'-"<<dd.inches<<"\"";
}
void engldisp(float dd) //for type float
{
int feet = int(dd)/12;
float inches = dd - float(feet)*12;
cout<<feet<<"\'"<<inches<<"\"";
}


Any suggestions?

Meltdown
25 Jun 2003, 8:07am
I turned the last 3 distance into ::distance and it compiled fine. Since my c++ knowledge is poor at best, I used my buddy google to come to that fix.

MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/c2872.asp) had some info about error c2872.
I guess the compiler didn't know if you wanted ::distance or std::distance(wild guess).

Since I'm not a C++ master, maybe someone who is can chime in and say if I'm way off base here.

kevin
26 Jun 2003, 5:06am
thx, it works.