Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4
Cats and dogs are both animals with some common points, here comes the need to use inheritance. But what should we write inside the functions of the Animal class, how many feet does an animal have ? What sound does an animal do ? So you can define this function as pure virtual function, it's as if you say, "i know all animals have this caracteristics but i can not define them in the general case". A class with at least one pure virtual function becomes an abstract class. You can not create object from this class but you can use inheritance, you can override the pure virtual functions and tou can use pointers to create heterogeneous containers. to learn more, you can also see articles about polymorphism, virtual and pure virtual function and inheritance if you are nor familiar with the concept ! Take a look at this code : https://code.sololearn.com/c3JVbuBy1g9B/?ref=app
12th Apr 2017, 2:19 PM
Glozi30
Glozi30 - avatar