虚函数的默认参数是静态绑定

   1: #include<iostream>
   2: #include<string>
   3: using namespace std;
   4: class Base
   5: {
   6: public:
   7:     virtual void Speak(string str="Base class")
   8:     {
   9:         cout<<"In base clsss ,the default str is "<<str<<endl;
  10:     }
  11: };
  12:  
  13: class Child:public Base
  14: {
  15: public:
  16:     void Speak(string str="child class")
  17:     {
  18:         cout<<"In child class,the default str is "<<str<<endl;
  19:     }
  20: };
  21:  
  22: int main()
  23: {
  24:     Base *pB = new Base();
  25:     Child *pC = new Child();
  26:     pB->Speak();
  27:     pC->Speak();
  28:     pB = new Child();
  29:     pB->Speak();
  30: }

22

原文地址:https://www.cnblogs.com/younes/p/1793302.html