Skip to content

Instantly share code, notes, and snippets.

@honux77
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save honux77/dc610bb25288fde7f501 to your computer and use it in GitHub Desktop.

Select an option

Save honux77/dc610bb25288fde7f501 to your computer and use it in GitHub Desktop.
c++ inheritance example
#include <iostream>
using namespace std;
class Base
{
public:
void foo1() {
cout << "BASE foo1" << endl;
}
virtual void foo2() {
cout << "Base foo2" << endl;
}
};
class Derived : public Base
{
public:
void foo1() {
cout << "Derived foo1" << endl;
}
void foo2(){
cout << "Derived foo2" << endl;
}
};
/**
* result of main is
* BASE foo1
* Derived foo2
* Derived foo2
* Derived foo2
**/
int main()
{
Base *bar = new Derived();
bar->foo1();
bar->foo2();
Derived *bar2 = new Derived();
bar2->foo1();
bar2->foo2();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment