Skip to content

Instantly share code, notes, and snippets.

@liuchang0812
Created June 12, 2016 12:25
Show Gist options
  • Save liuchang0812/a677d3e16f50151af219a2c09defb0fb to your computer and use it in GitHub Desktop.
Save liuchang0812/a677d3e16f50151af219a2c09defb0fb to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
class Base
{
public:
int Jiao()
{
return JiaoImpl();
}
private:
virtual int JiaoImpl() = 0;
};
class Dog: public Base
{
private:
virtual int JiaoImpl()
{
cout << "Wang" << endl;
}
};
class Cat: public Base
{
private:
virtual int JiaoImpl()
{
cout << "Miao" << endl;
}
};
int main()
{
Dog dg;
dg.Jiao();
Cat ct;
ct.Jiao();
Base* a = new Dog();
a->Jiao();
Base* b = new Cat();
b->Jiao();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment