Why is my class only returning the default constructor?

I defined my class using a constructor exactly as specified (or so I thought) but after attempting to initialize 4 points, my program still returns the default constructor. What am I doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  class Rectangle{
      private:
            int x1, x2, y1, y2;
      public:
             Rectangle(int a, int b, int c, int d){
                  a = x1;
                  b = x2;
                  c = y1;
                  d = y2;
                  };
             Rectangle(){
                  x1 = 1;
                  x2 = 1;
                  y1 = 1;
                  y2 = 1;
                  };        
             void setPoints(int a, int b, int c, int d){
                  a = x1;
                  b = x2;
                  c = y1;
                  d = y2;
                  };
             int getX1(){
                 return x1;
                 };
             int getX2(){
                 return x2;
                 };
             int getY1(){
                 return y1;
                 };
             int getY2(){
                 return y2;
                 };
             void printPoint1(){
                  cout << "(" << x1 << "," << x2;
                  };
             void printPoint2(){
                  cout << "(" << y1 << "," << y2;
                  };             
                 
      };

int main(int argc, char *argv[])
{
    Rectangle rect;
    rect.setPoints(100, 300, 250, 150);
    cout << "First point: (" << rect.getX1() << "," << rect.getY1() << ")" << endl;
    cout << "Second point: (" << rect.getX2() << "," << rect.getY2() << ")" << endl;
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
Lines 6-9 should be flipped. Same with lines 18-21. Also shouldn't line 36 and line 39 be ( x1 , y1 ) & ( x2 , y2 )?

*edit let me be a little more clear.
You have lines 6-9 and 18-21 backwards. Basically you are assigning the values of your private variables to the local values being passed into the function and as the function ends(they become out of scope) it kills the local variables so nothing is happening. You want to be copying the value of your local values to your private variables which will modify the current object.
Last edited on
You've got your assignments backward. Instead of a = x1; try x1 = a; etc.
Great! Thank you so much!
Topic archived. No new replies allowed.