C++ 繼承示例

#include
  #include<string>
  using namespace std;
  
  class dog
  {
  private:
   int age;
   string name;
  public:
   dog & SetAge(int a)
   {
   age=a;
   return *this;
   }
   int GetAge()
   {
   return age;
   }
   string GetName()
   {
   return name;
   }
   dog & SetName(string n)
   {
   name=n;
   return *this;
   }
   void call(int b)
   {
   cout << this << endl;
   }
  };
  class xiaoqiang :public dog
  {
  public:
   using dog::call ;//此處需聲明纔可以與基類的成員函數重載
   int call(int a,int b)
   {
   cout << this << endl;
   return 0;
   }
  };
  int main()
  {
   xiaoqiang tb;
   int res=tb.call (1,2);
   return 0;
  }
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章