virtual functions codebit | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

virtual functions codebit

https://www.sololearn.com/compiler-playground/c9069SBHc1dk in line 9 : virtual void speak() = 0; cant we declare this func as just void (without virtual) and why did we put = 0

22nd Dec 2022, 6:40 PM
Lalala
Lalala - avatar
1 ответ
+ 2
Yes. You can but no longer virtual function. It Becomes a normal function. virtual void speak() = 0; is making it pure virtual function, telling the compiler that is has no implementation. Derived class provides it's implementation. Making it virtual, provides Polimorphic feature that it invoke methods depends on the initialization.
23rd Dec 2022, 12:17 PM
Jayakrishna 🇮🇳