I do however have another question which relates to the original question, and it doesn't seem to be in my books.
I have this as my new Line header:
Code:
/* Line.h */
#ifndef _LINE_H
#define _LINE_H
#include "Point2D.h"
/**
A line represented by its slope and y-intercept.
*/
class Line{
private:
double mySlope; // the slope for this line
double myYIntercept; // the y-intercept for this line
;
public:
Line(double slope, double yIntercept);
Line(Point2D p1,Point2D p2);
~Line();
double getSlope();
double getYIntercept();
double calculateY(double xVal);
};
#endif
and this is my new main program:
Code:
#include <iostream>
#include "Line.h"
#include "Point2D.h"
int main (int argc, char * const argv[]) {
Line test(3.0, 4.5);
Point2D p1();
Point2D p2(3.0, 4.5);
Line test2(p1, p2);
std::cout << test.getSlope() << "\n";
std::cout << test.getYIntercept() << "\n";
std::cout << test.calculateY(5.0) << "\n";
std::cout << "Hello, World!\n";
return 0;
}
It is throwing an error on the "Line test2(p1, p2);" the error is that there is, "no matching function for call to 'Line::Line(Point2D(&)(), Point2D&)' "
I'm not recieving any errors in my Line.cpp file where I have defined the second constructor (which the problem line uses.) And there aren't any errors thrown from my Point2D class. While I realize that the lack of errors doesn't mean much I can't shake the feeling that there is a problem with how I am passing the objects to the constructor, or how I defined the constructor. Does anyone have an idea?
(here is the constructor)
Code:
//Constructs a line based on two points.
Line::Line(Point2D p1, Point2D p2){
mySlope = (p2.getY() - p1.getY())/(p2.getX() - p1.getX());
myYIntercept = p1.getY()-(p1.getX()*mySlope);
}
Many Thanks,
Norehsa