c++ - How do you approach a private variable from a different class -
void user :: buyapples(){ while(1){ cout<<"how many want buy? press 0 quit.";cin>>qq; if(qq==0) return ; if(qq<= f.getnumofapples()){ if(salary>=(qq*200)){ invofapples+=qq; salary-=(qq*200); showsalary(); } else{ cout<<"not enough money"<<endl; void homescreen(); } } else{ cout<<"there's not enough apples in stock"<<endl; continue; } } }
this code market qq being input using cin.
i can change salary , private variables in user
class.
but need change private variables in fruit class int numofapples
. how can change numofapples
?
i can't seem change variable user class. when tried change fruit class, qq doesn't carry over. do?
if want access private variable class should implement public method in class, get/set method example.
with preserve visibility of variable
Comments
Post a Comment