private by default : private « Class « C++ Tutorial






#include <iostream> 
using namespace std; 
 
class MyClass { 
  int i;   // private by default 
public: 
  int getI() { return i; } 
  void setI(int j) { i = j; } 
}; 
 
int main() 
{ 
  MyClass s; 
 
  s.setI(10); 
  cout << s.getI(); 
 
  return 0; 
}
10








9.9.private
9.9.1.private fields
9.9.2.private by default
9.9.3.Non-friend/non-member functions cannot access private data of a class
9.9.4.Using a class with private data members