I'm rather new to the C++ language and programming as a whole. I have a question with regards to creating a constructor that contains arguments that are objects of another class.
Example Constructor of an Object:
Point::Point(int x, int y)
{
//initiating the values of x and y...
}
Then now when I try to create a constructor that requires arguments of said Object from before, this is what I've come up with.
Line::Line(Point pt1, Point pt2):Point(x, y)
{
//initiating the values of the class...
}
This gives me an error where 'Point' is not a direct base of 'Line'. I get what it is trying to say as Line is not a derived class of Point. But how do I create a constructor that requires arguments that are objects from another class?
Any help would be appreciated.
Regards, yxt.
EDIT: as requested by some, here is the constructor for Line:
Line::Line(Point newPt1, Point newPt2)
{
pt1 = newPt1;
pt2 = newPt2;
}
EDIT2: I've managed to solve the problem. Huge thanks to the elaborate examples and explanations of @user1158692 , @Brian Gradin and @Tristan Brindle.
Lineclass look like?