C ++ day 15: polymorphism and virtual work 🔹 1. What is polymorphism? Polytestrality = "many forms". In C ++, it is mainly obtained: Ceremony surcharge (pre -covered) Ceremony overriding Virtual work 🔹 2. Function Overroid (Ricap) CPP Copy edit Class base { public: Zero greetings () {cout << "Hello base \ n"; , , Class derivative: Public base { public: Zero greetings () {cout << "Hello derived \ n"; , , 🔹 3. Virtual work Runtime allows polymorphism. Call the correct function through base class pointer/reference. CPP Copy edit Class animal { public: Virtual zero sound () { cout << "Animal sound \ N"; , , Class Dog: Public Animal { public: Zero sound () override { cout << "dog barks \ n"; , , int main() { Animal* a = new dog (); A-> sound (); // Dog bark Remove A; , 🔹 4. Pure virtual work and abstract class CPP Copy edit Class size { public: ...
C ++ Day 14: Types of Heritage and Protected Access 🔹 1. Types of heritage in c ++ Type details Single one base → a derivative class Multi -level base → derived1 → derived2 Many are inherited from a derived class 2+ base A base class ingested → Many derivative classes Two or more hybrid combination 📌 Single Heritage (Review) CPP Copy edit Class animal { public: Eat zero () { Cout << "Food ..." << Endl; , , Class Dog: Public Animal { public: Zero bark () { Cout << "Barking ..." << Endl; , , 📌 multilevel heritage CPP Copy edit Class living public: Zero Breath () {Cout << "Breath" << Endl; , , Class Animal: Public Living public: Eat zero () {cout << "eating" << endl; , , Class Dog: Public Animal { public: Zero bark () {cout << "barking" << endl; , , 📌 Many heritage CPP Copy edit Class printer { public: Zero print () {cout <...