C++ 多重继承&纯虚基类接口实现
1 #include <iostream> 2 3 using namespace std; 4 5 class TInterface1 6 { 7 public: 8 virtual void Sleep() = 0; 9 }; 10 class TInterface2 11 { 12 public: 13 virtual void Run() = 0; 14 }; 15 16 class Human :public TInterface1, public TInterface2 17 { 18 void Sleep() 19 { 20 cout << "sleep func" << endl; 21 } 22 void Run() 23 { 24 cout << "run func" << endl; 25 } 26 }; 27 28 29 int main() 30 { 31 Human hum; 32 TInterface1 *func1 = &hum; 33 TInterface2 *func2 = &hum; 34 35 func1->Sleep(); 36 func2->Run(); 37 }
运行输出:


浙公网安备 33010602011771号