Animal(string name) { m_name = name; } public: string getName() { return m_name; } virtual const char* speak() { return "???"; } }; class Cat: public Animal { public: Cat(string name) : Animal(name) { } virtual const char* speak() { return "Meowlib, Animal sinfi obyektlarini yaratishga imkon beradi. - speak() metodini qayta aniqlamaydigan avlod sinflari hali ham bo deydi ldi? Biz speak () metodini qayta aniqlashni unutib qolgan bir nechta narsa bor. Birinchidan, speak() endi sof virtual funktsiyadir. Bu shuni anglatadiki, Animal endi abstrakt ajdod-sinf bolmasa ham). Ikkinchidan, bizning Lion sinfimiz Animal sinfining avlodi bo says John deydi ymoqchi bolsak foydali bolmaydi. Talum bo= 0rifi bo; } Bunday holda, speak () hali ham sof virtual funktsiya hisoblanadi (garchi biz uni keyinroq aniqlagan bolgan har qanday sinf speak() metodini qayta aniqlashi kerak yoki u ham abstrakt sinf hisoblanadi. Sof virtual funktsiyani belgilashda uning tanasi (taladi. Masalan: #include #include using namespace std; class Animal{ //bu abstrakt sinf; protected: string m_name; public: Animal(string name) : m_name(name) { } string getName() { return m_name; } virtual const char* speak() = 0; //sof virtual funksiya