c++ - Set a value of a class from another class -
i'm trying set value of member of class class using snippet. here sample of code i'm trying make work
class { private: int a; public: a() { = 0; } a(int val) { = val; } int geta() { return a; } void seta() { = 290; } }; class b { b(){}; void setb() { a; a.seta(); } }; int main(){ a; b b; b.setb(); cout << b.geta(); } how can make code pint out 290.i prints out 0
in setb a variable temporary destroyed when function returns.
Comments
Post a Comment