What is the pure virtual definition in C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

What is the pure virtual definition in C++

22nd Oct 2016, 7:13 AM
Davillas
Davillas - avatar
2 Answers
+ 9
In a class/interface definition, a pure virtual function is one that doesn't have any definition (doesn't have any statements). The pure virtual functions must be implemented (and this is mandatory) in the subclasses in order to the subclasses to compile. The idea is to leave a blueprint of what the subclasses of a particular class/interface should implemented to have a common functionality between all the impplementations. The syntax is as follows: virtual return_type function_name(args) = 0; where return_type if the data type to be returned (void if it has no return), function_name is the name of you function and args the list of arguments if apply.
24th Oct 2016, 6:24 PM
Nelson Urbina
Nelson Urbina - avatar
+ 6
Thank you for detailed answer!
26th Oct 2016, 4:11 AM
Davillas
Davillas - avatar