Created
June 12, 2016 12:25
-
-
Save liuchang0812/a677d3e16f50151af219a2c09defb0fb to your computer and use it in GitHub Desktop.
This file contains 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> | |
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