Rules for Access to data members or to member functions of a class?

hi,
Given the following statement by the Client class,

1
2
3
4
5
6
7
8
9
10
11
12
class Client {
private:
float solde; // private datapublic:
string name; // public data
….
// member functions (public)
float getSolde() {return solde; }
void putSolde(float x) {solde = x;}
….
};



which of the following statements are unacceptable? Why?

1
2
3
4
5
6
Client c1, c2;
cout<<"Name de c1:"<<c1.name;
cout<<"Solde de c1:"<<c1.solde;
cout<<"Solde de c1:"<<c1.getSolde();
c2.solde=0;
c2.putSolde(12359.142);


I need help :)

solde is private. You can't use it outside of class for read and write.
Other is public, i.e. ok.
1
2
3
4
5
6
Client c1, c2;
cout<<"Name de c1:"<<c1.name; //ok
cout<<"Solde de c1:"<<c1.solde; //no
cout<<"Solde de c1:"<<c1.getSolde(); ok
c2.solde=0; //no
c2.putSolde(12359.142); ok
thank you very much :)
Topic archived. No new replies allowed.