#include #include #include class ImportantObject { public: ImportantObject(); ImportantObject(int nObj); ~ImportantObject(); int GetObject(); void PutObject(int nObj); protected: int Object; }; // Inserting public here tells C that all inherited members are public by default class NotSoImportantObject : public ImportantObject { public: void ScrewObject(); }; ImportantObject::ImportantObject() { Object = 0; } ImportantObject::ImportantObject(int nObj) { Object = nObj; } ImportantObject::~ImportantObject() { // There's nothing to clean up in this example, but if there were, now is the time } int ImportantObject::GetObject() { return Object; } void ImportantObject::PutObject(int nObj) { if (Object < nObj) { Object = nObj; } } void NotSoImportantObject::ScrewObject() { // This function will screw up the object :) Object += 15; Object >>= 2; Object -= 1; } // Now that all the code is in place for the class, here's some demo code: int main() { ImportantObject a, b; NotSoImportantObject c; a.PutObject(5); printf("a contains object: %d\n", a.GetObject()); a.PutObject(3); printf("a still contains object: %d\n", a.GetObject()); b.PutObject(3); printf("b contains object: %d\n", b.GetObject()); b.PutObject(52); printf("Now, b contains %d\n", b.GetObject()); for (int i = 0; i < 15; i++) { c.PutObject(i); printf("C = %d\t", c.GetObject()); c.ScrewObject(); printf(" then C = %d\n", c.GetObject()); } printf("Get the idea?\n"); getch(); return 0; }