why do we use private functions ?

i am pretty new to cpp , so i would like to have a bit detailed explanation.
if we use the scope operator for restricting the use of a function to a given class, then why do we need private functions ? has any of these methods for "imposing restrictions" a better over the other ?
what do you mean by scope operator?

Private is useful for defining a method that can only be used by the class it belongs to. This is the same with protected, but a private method will not be inherited by any child classes while a protected one will. Thats the diff.
The scope resolution operator :: is used to resolve objects in namespaces. A class is a sort of built-in namespace, so it works the same way.

Everything in a namespace is visible. You just need to reference it properly (by full name or by "namespace using" or the like).

But like Zaita said, the items in a class can have their visibility restricted:

public - no restrictions (anyone can see it)
protected - only the class and its descendant classes can see it
private - only the class itself can see it

These visibilities are important in maintaining data integrity and encapsulation.

Hope this helps.
Topic archived. No new replies allowed.