Skip to content

Instantly share code, notes, and snippets.

@dmikurube
Created December 19, 2014 07:46
Show Gist options
  • Save dmikurube/d35e9287e216377bf51e to your computer and use it in GitHub Desktop.
Save dmikurube/d35e9287e216377bf51e to your computer and use it in GitHub Desktop.
#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