[C++] c++ 隐藏方法 →→→→→进入此内容的聊天室

来自 , 2019-04-22, 写在 C++, 查看 110 次.
URL http://www.code666.cn/view/96c5c28b
  1. #include <iostream>
  2. using std::cout;
  3.  
  4. class Mammal {
  5. public:
  6.         void Move() const {
  7.                 cout << "Mammal move one step.\n";
  8.         }
  9.         void Move(int distance) const {
  10.                 cout << "Mammal move ";
  11.                 cout << distance << " steps.\n";
  12.         }
  13. protected:
  14.         int itsAge;
  15.         int itsWeight;
  16. };
  17.  
  18. class Dog: public Mammal {
  19. public:
  20.         // You might receive a warning that you are hiding a function!
  21.         void Move() const {
  22.                 cout << "Dog move 5 steps.\n";
  23.         }
  24. };
  25.  
  26. int main() {
  27.         Mammal bigAnimal;
  28.         Dog Fido;
  29.         bigAnimal.Move();
  30.         bigAnimal.Move(2);
  31.         Fido.Move();
  32.         // Fido.Move(10);
  33.         return 0;
  34. }
  35.  

回复 "c++ 隐藏方法"

这儿你可以回复上面这条便签

captcha