The virtual function is a member function that expects to be overridden in a derived class.
Virtual function is a function in C++ program language or any object-oriented programming. This function is to redefined in derived classes.
The overridden or redefined in derived classes it mean the function in derived class will be executed than in the base class for every time the user refer the derived class to the base class.
For example with the code is,
class Base {
public:
void print() {
cout << "Base" << endl;
}
};
class Derived : public Base {
public:
void print() {
cout << "Derived" << endl;
}
};
So, when user pointer the base to object of derived class the result is "Base" than "Derived". So, this is the role of the virtual function it will make the result to "Derived" than "Base".
Learn more about derived class here:
brainly.com/question/27791611
#SPJ4