C++切除问题
C++中的 "override" - 简书 (jianshu.com)
1 #include <iostream> 2 3 using namespace std; 4 5 class Hum 6 { 7 protected: 8 string name; 9 public: 10 Hum(string name) 11 :name(name) 12 { 13 cout << "hum 构造" << endl; 14 } 15 virtual void Skill() 16 { 17 cout << name << ": hum skill" << endl; 18 } 19 }; 20 21 class Child : public Hum 22 { 23 public: 24 Child(string name) 25 :Hum(name) 26 { 27 28 } 29 void Skill() override 30 { 31 cout << name << ": Child skill" << endl; 32 } 33 private: 34 35 }; 36 int main() 37 { 38 Hum a = Child("cc"); 39 a.Skill(); 40 41 Child b("cc"); 42 Hum& A = b; 43 A.Skill(); 44 45 Hum *c = &b; 46 c->Skill(); 47 }