private fields : private « Class « C++ Tutorial





#include <iostream> 
using namespace std; 
 
struct MyClass { 
  int getI() { return i; } // these are public by default 
  void setI(int j) { i = j; } 
private: 
  int i;    
}; 
 
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