Created
December 19, 2014 07:46
-
-
Save dmikurube/d35e9287e216377bf51e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Base { | |
public: | |
virtual int func() { | |
return 0; | |
} | |
}; | |
class Derived1 : public Base { | |
public: | |
virtual int func() { | |
return 1; | |
} | |
}; | |
int main() { | |
Base b; | |
Derived1 d1; | |
std::cout << b.func() << std::endl; | |
std::cout << d1.func() << std::endl; | |
b = d1; | |
std::cout << b.func() << std::endl; | |
Base& b2 = d1; | |
std::cout << b2.func() << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment