Again I come crawling for help...

I made a program that makes coordiant points and lines with these coordinates. A new class is going to inherit from the class with the lines, and calculate the distance between a line segment and a point. I found the correct mathematical formula. With that I first calculate the distance between two points to get the length of the line segment. And this is where the problem is:

#include <iostream>
#include <math.h>

using namespace std;

class Calculating: public Line
	double distX;
	double distY;

	Arvingen() {} 

	double distance()
		distX = (x - x); // How do I make this x2-x1?
		distY = (y - y); // How do I make this y2-y1?
		dist2D = sqrt((distX*distX) + (distY*distY));

		return dist2D;
}; // end class

The constructor in Line:


	for(int i = 0;i <= 4;i ++)
		x = rand() % 10 + 1;
		y = rand() % 10 + 1;

		linje2D[i].set2D(x, y);
		bpunkt[i].set2D(x, y);

I've tried to get the distX and distY correct by using a for-loop and various other things like that, but all I get is a "expression must have pointer-to-object type".


6 Years
Discussion Span
Last Post by Tiny_trixer

Seems to me your line class should contain the start and end points for a line. Then pass in a point to your "distance" method in Calculating. Seem like you might want a Point class too, perhaps...


I have a Point class. I just didn't post it since the Calculating is inheriting from Line and not Point. :)

But, ok. That sounds like a good idea. I didn't think past "making some points". I'll try editing the Line-class to make start and end points instead of random points.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.