my copy from a "class" tutorial giving weird results



solved


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
#include <iostream>
using namespace std;

class Rectangle
{
private:
      int x;
      int y;
      
public:
       void set_values(int a, int b)
       {
            x = a;
            y = b;
       }
       
       int area()
       {
           return x * y;
       }
};

int main()
{
    Rectangle rect;
    Rectangle rect_2;
    
    rect.set_values(3 , 4);
    cout << "Area(rectangle 1): " << rect.area() << endl;
    rect.set_values(5 , 500);
    cout << "Area(rectangle 2): " << rect_2.area() << endl;
    
    system("PAUSE");
}


Thanks for taking a look.

Last edited on
On line 30 you are setting the values of rect again, not rect_2.
wow man, epic fail

thanks xD
No problem. ^_^
Topic archived. No new replies allowed.