# Need Help!!! Stumped



## dcf-joe (Feb 25, 2010)

The entire programming exercise is supposed to find the distance between two points in 3D space. Every file that is included is necessary per instructor guidelines. I have fixed everything down to 5 seemingly simple errors:



> error C2504: 'MyPoint' : base class undefined
> error C2065: 'x' : undeclared identifier
> error C2065: 'y' : undeclared identifier
> error C2065: 'x' : undeclared identifier
> error C2065: 'y' : undeclared identifier



However, that base class is defined, blatantly. Here is all of the source code:

*Main Program*

```
#include <iostream>
#include <cmath>
#include "MyPoint.h"
#include "ThreeDPoint.h"
using namespace std;

double getDistance(ThreeDPoint &points1, 
		           ThreeDPoint &points2)
{
	return sqrt(pow((points1.getX() - points2.getX()), 2.0) +
		        pow((points1.getY() - points2.getY()), 2.0) +
				pow((points1.getZ() - points2.getZ()), 2.0));
}

int main()
{
	ThreeDPoint set1(0.0, 0.0, 0.0);
	ThreeDPoint set2(10.0, 30.0, 25.5);

	cout << getDistance(set1, set2);
	return 0;
}
```

*MyPoint Implementation*

```
#include "MyPoint.h"

MyPoint::MyPoint()
{
	x = 0.0;
	y = 0.0;
}

MyPoint::MyPoint(double newX, double newY)
{
	x = newX;
	y = newY;
}

double MyPoint::getX()
{
	return x;
}

double MyPoint::getY()
{
	return y;
}
```

*MyPoint Class Definition*

```
#ifndef MYPOINT_H
#define MYPOINT_H

class MyPoint
{
private:
	double x, y;

public:
	friend class ThreeDPoint;
	
	MyPoint();
	MyPoint(double, double);

	double getX();
	double getY();
};

#endif
```

*ThreeDPoint Implementation*

```
#include "ThreeDPoint.h"

ThreeDPoint::ThreeDPoint()
{
	x = 0.0;
	y = 0.0;
	z = 0.0;
}

ThreeDPoint::ThreeDPoint(double newX, double newY, double newZ)
{
	x = newX;
	y = newY;
	z = newZ;
}

double ThreeDPoint::getZ()
{
	return z;
}
```

*ThreeDPoint Class Declaration*

```
#ifndef THREEDPOINT_H
#define THREEDPOINT_H

class ThreeDPoint:   public MyPoint
{
private:
	double z;

public:
	ThreeDPoint();
	ThreeDPoint(double, double, double);
	
	double getZ();
	//double getDistance(); 
};

#endif
```


----------



## ste2425 (Feb 25, 2010)

im only a newd at programming, but i dont see any variable declerations, u no like int bla bla bla...
just my input, as ive said im a newd an probs missed summit.


----------



## dcf-joe (Feb 25, 2010)

Can you specify where you saw that, because I declared and all of that in my class declaration files.


----------



## ste2425 (Feb 26, 2010)

wait a min youve declared then in that class. That class is within a seperate .h file right?
If my understanding of this is correct, which it probs aint. Variables only reside in the function they are created within. So if you try to call a variable created in a different function ul get the build errors your getting. There is a way of declaring variables i think for the whole. Outside on main(). But like i said i could and most probably am wrong


----------



## dcf-joe (Feb 26, 2010)

Thank You ste2425 for your input, but my mistake was much more simpler

If you look at my *ThreeDPoint* class declaration file, I forgot to put "#include "MyPoint.h" 

After putting that in, I removed my friend class statement and changed some variables from private status to protected status

NOW IT WORKS!!!


----------



## ste2425 (Feb 26, 2010)

haha well im glad you gotit sorted out


----------

