if you declare it in private scope, then it will not be accessible outside of the class (it can only be accessed by member and methods of the same class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
class X
{
private :
int data_; // private member
public : //< the methods below are declared public, they can be accesible outside the class
// to access a private member, we should use
// a so called "getter/setter" method
void setData( int data ) { data_ = data; } // setter (can access data_ since this method is a member)
int getData( ) const { return data_; } // getter
};
int main()
{
X x;
x.data = 10; // <!! Illegal
x.setData( 10 ); // < Legal
}