Created
May 2, 2012 06:53
-
-
Save dmikurube/2574603 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
class Parent { | |
public: | |
int x; | |
virtual void print() { std::cout << "Parent" << std::endl; } | |
}; | |
class Child: public Parent { | |
public: | |
int y; | |
virtual void print() { std::cout << "Child" << std::endl; } | |
}; | |
int main() { | |
Parent p; | |
Child c; | |
Parent p2 = Child(); | |
Parent *p3 = new Child(); | |
p.print(); // Parent | |
c.print(); // Child | |
p2.print(); // Parent | |
p3->print(); // Child | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment