Skip to content

Instantly share code, notes, and snippets.

@berkus
Created May 19, 2014 04:57
Show Gist options
  • Save berkus/7b7f14bc9cb089f610f7 to your computer and use it in GitHub Desktop.
Save berkus/7b7f14bc9cb089f610f7 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
class VirtBase
{
public:
virtual void test() = 0;
};
class Derived : public VirtBase
{
typedef VirtBase super;
public:
void test() override;
};
void VirtBase::test()
{
cout << "VirtBase" << endl;
}
void Derived::test()
{
super::test(); // You cannot call base function by pointer since it is declared pure virtual,
// but you can still call it statically which is the whole point of this implementation.
cout << "Derived" << endl;
}
int main()
{
VirtBase* cls = new Derived;
cls->test();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment