#include <iostream>
using namespace std;
class CRectangle {
int x, y;
public:
void set_values (int,int);
int area () {return (x*y);}
};
void CRectangle::set_values (int a, int b) {
x = a;
y = b;
}
int main () {
CRectangle rect, rectb;
rect.set_values (3,4);
rectb.set_values (5,6);
cout << "rect area: " << rect.area() << endl;
cout << "rectb area: " << rectb.area() << endl;
return 0;
}
In the above code I am confused on the lines from rect.set_values to cout<<
After rect.set_values(3,4) is executed are the values 3 and 4 stored in the variables "x" and "y" ?
and then when rectb.setvalues(5,6) is executed are the variables "x" and "y" overwritten with "5" and "6"?
If that is true then how come when the cout<< 's are executed afterwards they each have a different value?
Thanks, if my question does not make sense, please tell me I will try to be more clear.
EDITED: NEVERMIND
I think I just understood it.
rectb and rect are different variables so basically the class that was defined is a general one which is a definition for each variable. So each variable has a different class thats "template" is the one shown at the top. So I guess the set_values stores the numbers in "x" and "y" which are different for each variable.
If thats right then I guess the thread can be closed, sorry about that