未完待续
Posted CreatorKou
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了未完待续相关的知识,希望对你有一定的参考价值。
1 #include <iostream> 2 #include<typeinfo> 3 #include<vector> 4 5 using namespace std; 6 7 class Base{ 8 public: 9 virtual void fun(){cout << "Base::fun\\n";} 10 }; 11 class Derived : public Base{ 12 public: 13 void fun(int i){cout << "Derived the i = " << i << endl;} 14 }; 15 class Sunzi : public Derived{ 16 public: 17 void fun(){cout << "in Sunzi\\n";} 18 }; 19 20 int main() 21 { 22 Derived de; 23 de.fun(1); 24 //de.fun(); //error 25 Sunzi sun; 26 sun.fun(); 27 Base *ba = &sun; 28 ba->fun(); 29 return 0; 30 }
1 #include <iostream> 2 #include<typeinfo> 3 #include<vector> 4 5 using namespace std; 6 7 class Base{ 8 public: 9 virtual void fun(){cout << "Base::fun\\n";} 10 }; 11 class Derived : public Base{ 12 public: 13 void fun(){cout << "in Derived\\n";} 14 void fun(int i){cout << "Derived the i = " << i << endl;} 15 }; 16 class Sunzi : public Derived{ 17 public: 18 void fun(){cout << "in Sunzi\\n";} 19 void fun(int i){cout << "Sunzi the i = " << i << endl;} 20 }; 21 22 int main() 23 { 24 Derived *de = new Derived(); 25 Derived de2; 26 Base *ba; 27 Sunzi sun; 28 // 29 de->fun(1); 30 de->fun(); //error 31 32 ba = &de2; 33 ba->fun(); 34 35 sun.fun(); 36 37 ba = &sun; 38 ba->fun(); 39 40 de = &sun; 41 de->fun(); 42 de->fun(1); 43 return 0; 44 }
#include <iostream> #include<typeinfo> #include<vector> using namespace std; class Base{ public: virtual void fun(){cout << "Base::fun\\n";} }; class Derived : public Base{ public: using Base::fun; //using solve redefine void fun(int i){cout << "Derived the i = " << i << endl;} }; class Sunzi : public Derived{ public: void fun(){cout << "in Sunzi\\n";} }; int main() { Derived de; de.fun(1); de.fun(); //ok Sunzi sun; sun.fun(); Base *ba = &sun; ba->fun(); return 0; }
#include <iostream> #include<typeinfo> #include<vector> using namespace std; class Base{ public: virtual void fun(){cout << "Base::fun\\n";} virtual void fun(int i){cout << "Base:: i = " << i << endl;} }; class Derived : public Base{ public: void fun(){cout << "in Derived\\n";} void fun(int i){cout << "Derived the i = " << i << endl;} }; int main() { Base *ba; Derived de; de.fun(1); de.fun(); //ok ba = &de; ba->fun(); ba->fun(1); return 0; }
以上是关于未完待续的主要内容,如果未能解决你的问题,请参考以下文章