Bruce Eckel's Thinking in C++, 2nd Ed | Contents | Prev | Next |
//: C05:Public.cpp {O} // Public is just like C struct struct A { int i; char j; float f; void func(); }; void A::func() {} struct B { public: int i; char j; float f; void func(); }; void B::func() {} ///:~
//: C05:Private.cpp // Setting the boundary struct B { private: char j; float f; public: int i; void func(); }; void B::func() { i = 0; j = '0'; f = 0.0; }; int main() { B b; b.i = 1; // OK, public //! b.j = '1'; // Illegal, private //! b.f = 1.0; // Illegal, private } ///:~