Problem has been fixed! Thank you!
My copy constructor doesn't seem to work (I've tried the same constructor I've used for a previous project):
public Rectangle(Rectangle Rectangle)
{
bottomleft = Rectangle.bottomleft;
topright = Rectangle.topright;
}
basically I have a class called Rectangle, that takes two points (bottomleft point and topright point - the rectangle is parallel/perpendicular to the X/Y axis).
I tested this copy constructor by creating a new rectangle, and moving the new rectangle's coordinates by 3. however when I did .toString() to the first rectangle and the second, the coordinates on both were shifted, rather than just the second rectangle!
Here's what I did:
Point bottom = new Point(0, 0); // a class that stores two 'double' objects (double x, double y)
Point top = new Point(5, 5);
Rectangle first = new Rectangle(bottom,top); // creates new rectangle, horizontal lines are parallel to X axis, vertical are parallel to Y axis
Rectangle second = new Rectangle(first); // attempt to use copy constructor
second.Move(3, 3); // moves the second rectangle three units up and three units to the right
Console.WriteLine(first.ToString()+"\n"+second.ToString()); // posts the coordinates of the two rectangles
The expected output would be (0,0),(5,5) for the first rectangle, and (3,3)(8,8) for the second, but instead the output is (3,3),(8,8) for both rectangles, meaning that both were changed.
How do I fix my copy constructor (posted above)?
Problem has been fixed! Thank you! As per common suggestion, I used a copy constructor on the 'Point' class as well. I'm leaving this question in case it helps someone in the future.
My Point class has a copy constructor of it's own (nearly identical to the one I posted above), and I modified my Rectangular constructor to be like this:
public Rectangle(Rectangle Rectangle)
{
Point a = new Point(Rectangle.GetBottomPoint());
Point b = new Point(Rectangle.GetTopPoint());
this.bottomleft = a;
this.topright = b;
}