Computer Science, asked by mahalakshmi524, 1 year ago

What are pure virtual functions? How are they different from normal functions in c++? Explain with an example

Answers

Answered by pushpa2429
1
Abstract classes cannot be instantiated. Derived classes need to override/implement all inherited pure virtual functions. Ifthey do not, they too will become abstract. An interesting 'feature' of C++ is that a class can define apure virtual function that has an implementation.

mahalakshmi524: can you explain with an example
Answered by Anonymous
2

Virtual Function and Pure Virtual Function differs in declaration.

Virtual Function is declared with keyword 'virtual' at the start of declaration.

Ex : virtual return_type function_name(function arguments);

While Pure Virtual Function is declared as

Ex : virtual return_type function_name(function arguments) = 0;

NOTE : Sometime it has been written that pure virtual function has no function body. But this is not always true. Having a default definition of pure virtual function is not common but its possible.

Ex : virtual return_type function_name(function arguments) = 0; //Declaration

return_type class_name::function_name(function argument) //Definition

{

.

.

.

}

Virtual Function and Pure Virtual Function differs in use also.

Thanks


mahalakshmi524: i want the difference between normal function and pure virtual function
Similar questions