I\'m a total newbie with tons of ?\'s in my mind and a lot to experience with C++ yet! There\'s been something which I find really confusing and it\'s the use of public vari
OK, As I understand, your question is this: Why make a variable private and then make two functions which just retrieve the value and set the value without any checks? If there were checks, you'd understand, wouldn't you? For example, if you set the hour field of a Time class, checking that hour <= 24 is a good idea.
But when no checks are applied the idea is this: if at some point you decide to change the setting and getting functions, for example, perform some checks in them, the whole code that has been using your class need not be recompiled
Also, the general purpose of encapsulation is that one communicate with the class only via its interface, without knowing how it is implemented. The more inner info you hide, the better.
When do you use public variables? When you make objects that have no behavior. Ones that are just a conglomerate of data. For example, see std::pair. A pair is just a struct, with public first and second.
In general, one cannot give a strict criteria when to use which way, but you'll feel it yourself with gain of experience.
HTh