0 votes
in C Plus Plus by

What are Virtual Functions?

1 Answer

0 votes
by

A virtual function allows the derived classes to replace the implementation provided by the base class.

Whenever we have functions with the same name in the base as well as derived class, there arises an ambiguity when we try to access the child class object using a base class pointer. As we are using a base class pointer, the function that is called is the base class function with the same name.

To correct this ambiguity we use the keyword “virtual” before the function prototype in the base class. In other words, we make this polymorphic function Virtual. By using a Virtual function, we can remove the ambiguity and we can access all the child class functions correctly using a base class pointer.

Related questions

+1 vote
0 votes
asked Mar 17, 2020 in C Plus Plus by rajeshsharma
0 votes
asked Jan 6 in C Plus Plus by GeorgeBell
...