Edit: looks like you solved it while I was typing. Yes, that's right - glad we could help ;)
Original post:
No, but you're close. pt1 is an actual Point2D, not Line2D. You would use the getX and getY member functions. Since you're killing me slowly, I'll just write the line here:
In file included from Point3D.h:5,
from Line3D.h:6:
Point2D.h:9: error: redefinition of ‘class Point2D’
Point2D.h:10: error: previous definition of ‘class Point2D’
In file included from Line2D.h:5,
from Line3D.h:7:
Point2D.h:9: error: redefinition of ‘class Point2D’
Point2D.h:10: error: previous definition of ‘class Point2D’
Line3D.cpp: In constructor ‘Line3D::Line3D(Point3D, Point3D)’:
Line3D.cpp:5: error: no matching function for call to ‘Line2D::Line2D()’
Line2D.h:20: note: candidates are: Line2D::Line2D(Point2D, Point2D)
Line2D.h:10: note: Line2D::Line2D(const Line2D&)
Line3D.cpp:5: error: no matching function for call to ‘Point3D::Point3D()’
Point3D.h:16: note: candidates are: Point3D::Point3D(int, int, int)
Point3D.h:10: note: Point3D::Point3D(const Point3D&)
Line3D.cpp:5: error: no matching function for call to ‘Point3D::Point3D()’
Point3D.h:16: note: candidates are: Point3D::Point3D(int, int, int)
Point3D.h:10: note: Point3D::Point3D(const Point3D&)
Just FYI I've referred back to your 1st post and now reduce the errors to as follows. :)
In file included from Point3D.h:5,
from Line3D.h:6:
Point2D.h:9: error: redefinition of ‘class Point2D’
Point2D.h:10: error: previous definition of ‘class Point2D’
In file included from Line2D.h:5,
from Line3D.h:7:
Point2D.h:9: error: redefinition of ‘class Point2D’
Point2D.h:10: error: previous definition of ‘class Point2D’
Line3D.cpp: In constructor ‘Line3D::Line3D(Point3D, Point3D)’:
Line3D.cpp:5: error: no matching function for call to ‘Line2D::Line2D()’
Line2D.h:20: note: candidates are: Line2D::Line2D(Point2D, Point2D)
Line2D.h:10: note: Line2D::Line2D(const Line2D&)
I'm now left with these error, can anyone please advise or assist? please....
In file included from Point3D.h:5,
from Line3D.h:7:
Point2D.h:9: error: redefinition of ‘class Point2D’
Point2D.h:10: error: previous definition of ‘class Point2D’
Line3D.cpp: In constructor ‘Line3D::Line3D(Point3D, Point3D)’:
Line3D.cpp:5: error: no matching function for call to ‘Line2D::Line2D()’
Line2D.h:20: note: candidates are: Line2D::Line2D(Point2D, Point2D)
Line2D.h:10: note: Line2D::Line2D(const Line2D&)
Your Line3D class inherits from Line2D. This means that when you create an object of Line 3D, it implicitly calls a constructor on Line2D.
Your constructor for Line3D doesn't specify how to construct Line2D, so the compiler is assuming you want it to call a default constructor on Line2D, i.e. one that takes no parameters. You haven't defined one, so it is failing.
Your constructor for Line3D needs to specify how to use the Line2D constructor you have defined.
Your code should look something like:
1 2 3 4 5 6 7
Line3D::Line3D(Point3D point1, Point3D point2)
: Line2D(/*Put the arguments to the desired Line2D constructor here*/),
pt1(point1),
pt2(point2)
{
/* Contents of your constructor */
}
And, please, when posting code to this forum, could you use the code tags? After all, you want us to be able to read your code easily, right? To create the tags, use the "<>" button to the right of the edit window, and then put your code between the tags.
Yes, it reduce more errors. Now I'm just left with 1 problem if I'm not wrong. Which is to make use to the #include guard. I'm not really how how to use the include guard. But here are my remaining errors
In file included from Point3D.h:5,
from Line3D.h:7:
Point2D.h:11: error: redefinition of ‘class Point2D’
Point2D.h:12: error: previous definition of ‘class Point2D’
Include guards stop you accidentally including the body of a header file more than once in a single source code file. In your case, one of your source files is including "Point2D.h" twice.
You use preprocessor directives to prevent this happening. The Wiki link Peter posted contains a clear example of how to do this.
You should do it as a matter of course in pretty much every single header file you ever write.