Computer Science, asked by cutybabystar6536, 1 year ago

What is the purpose of virtual function ? State the rules for virtual function.

Answers

Answered by Sangitasinha
4

hope this helps you. please mark me as brainlist and follow me

Attachments:
Answered by ImpressAgreeable4985
0

Answer:

provides the ability to define a function in a base class and have a function of the same name and type in a derived class called

Explanation:

The virtual function provides the ability to define a function in a base class and have a function of the same name and type in a derived class called when a user calls the base class function.

Rules of Virtual Function

Virtual functions must be members of some class.

Virtual functions cannot be static members.

They are accessed through object pointers.

They can be a friend of another class.

A virtual function must be defined in the base class, even though it is not used.

The prototypes of a virtual function of the base class and all the derived classes must be identical. If the two functions with the same name but different prototypes, C++ will consider them as the overloaded functions.

We cannot have a virtual constructor, but we can have a virtual destructor

Consider the situation when we don't use the virtual keyword.

Similar questions