class My_Class
{
// declaration of public members
public :
int val_1 ;
int val_2 ;
.
.
.
.
// constructor
My_Class(int val_1, int val_2, ...) ;
};
We all know that val_1 and val_2 and all other members are here public and therefore can be access (read and modified) from outside the class.
If I change these to private, they will not be accessible at all from outside the class.
However, I would like to define all of them such a way that
1 - they can be read and modified from inside the class
2 - but they can be "read only" from outside the class. They somehow appear as const int from outside the class.
Of couse, it is possible to define the methods get_var_1(), get_var_2(), ... and so on, that would be define as
int My_Class :: get_var_1()
{
return var_1 ;
}
However, I don't want to define a method for each of the variable. I can have a lot of them.