23-PolyAndNonPolymorphism

23-PolyAndNonPolymorphism - pointer->Virtual(); pointer...

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

View Full Document Right Arrow Icon
#include <iostream> using namespace std; class Level1 { public: void Print() { cout << "Level1" << endl; } virtual void Virtual() { cout << "Virt Level1" << endl; } }; class Level2 : public Level1 { public: void Print() { cout << "Level2" << endl; } virtual void Virtual() { cout << "Virt Level2" << endl; } }; class Level3 : public Level2 { public: void Print() { cout << "Level3" << endl; } virtual void Virtual() { cout << "Virt Level3" << endl; } }; int main (void) { Level1 one1; Level2 two2; Level3 three3; one1.Print(); one1.Virtual(); two2.Print(); two2.Virtual(); three3.Print(); three3.Virtual(); Level1* pointer = &one1; pointer->Print();
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: pointer->Virtual(); pointer = &two2; pointer->Print(); pointer->Virtual(); pointer = &three3; pointer->Print(); pointer->Virtual(); Level1 nonPointer = one1; nonPointer.Print(); nonPointer.Virtual(); nonPointer = two2; nonPointer.Print(); nonPointer.Virtual(); nonPointer = three3; nonPointer.Print(); nonPointer.Virtual(); return 0; } /* Level1 Virt Level1 Level2 Virt Level2 Level3 Virt Level3 Level1 Virt Level1 Level1 Virt Level2 Level1 Virt Level3 Level1 Virt Level1 Level1 Virt Level1 Level1 Virt Level1 Press any key to continue . . . */...
View Full Document

This note was uploaded on 10/05/2011 for the course CS 37 taught by Professor Glenncuevas during the Summer '09 term at Irvine Valley College.

Page1 / 2

23-PolyAndNonPolymorphism - pointer->Virtual(); pointer...

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

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