分类: C/C++
2006-07-06 12:17:18
class Person { ... }; class Student: private Person { ... }; // inheritance is now private void eat(const Person& p); // anyone can eat void study(const Student& s); // only students study Person p; // p is a Person Student s; // s is a Student eat(p); // fine, p is a Person eat(s); // error! a Student isn't a Person |
class Timer { public: explicit Timer(int tickFrequency); virtual void onTick() const; // automatically called for each tick ... }; |
class Widget: private Timer { private: virtual void onTick() const; // look at Widget usage data, etc. ... }; |
class Widget { private: class WidgetTimer: public Timer { public: virtual void onTick() const; ... }; WidgetTimer timer; ... }; |
class Empty {}; // has no data, so objects should // use no memory class HoldsAnInt { // should need only space for an int private: int x; Empty e; // should require no memory }; |
class HoldsAnInt: private Empty { private: int x; }; |