22-MultipleInheritance

22-MultipleInheritance - / Multiple inheritence: Inheriting...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
// Multiple inheritence: Inheriting from multiple classes #include <iostream> using namespace std; class BaseClass { public: int publicInt; BaseClass (int p = 0) { publicInt = p; } void printBase() { cout << publicInt << endl; } }; class DerivedClass : public BaseClass { public: int publicInt; DerivedClass(int p) { publicInt = p; } void printDerived() { cout << publicInt << endl; } void printBoth() { cout << BaseClass::publicInt << endl << publicInt << endl; } }; class Human { private: char name[20]; float age; public: int state; Human(char name[] = "", float age = 0.0f) { strcpy(this->name, name); this->age = age; state = 2; // Sleeping, working, studying, playing } void chooseRestaurant(bool randomFactor) { { // not hungry cout << "Not gonna go to a restaurant\n"; } { cout << "Wake up and nuke something\n"; }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
else if (state < 3) { cout << "I don't know which restaurant to choose\n"; }
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

22-MultipleInheritance - / Multiple inheritence: Inheriting...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online