Class problems!

I'm new here, nice to meet you guy!

Here's my exercise:

#include <iostream>
#include <cmath>
using namespace std;
class ThreeD
{
double x;
double y;
double z;
public:
ThreeD(double i,double j,double k)
{
x=i;
y=j;
z=k;
}
void show() const;
double distance(ThreeD a,ThreeD b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}
};
int main()
{
ThreeD a(1,0,2);
ThreeD b(3,6,9);
a.show();
b.show();
double r = distance(a,b);
cout << "Distance is " << r << endl;
system("Pause");
return 0;
}

void ThreeD::show() const
{
cout << "x: " << x << endl;
cout << "y: " << y << endl;
cout << "z: " << z << endl;
}

I don't know what's wrong with these lines of code!
Please help me!
Thanks guy!

Last edited on
I looks like that distance() is a method of the ThreeD class so you need to call a.distance(a, b). You can't just call it on it's own because it's not a global function.
thanks so much! I understand now!
Topic archived. No new replies allowed.