In C++, once a member function is declared as a virtual function in a base class, it becomes virtual in every class derived from that base class. In other words, it is not necessary to use the keyword virtual in the derived class while declaring redefined versions of the virtual base class function.
For example, the following program prints “C::fun() called” as B::fun() becomes virtual automatically.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Can static functions be virtual in C++?
- Virtual Destructor
- Catching base and derived classes as exceptions
- Nested Classes in C++
- Functions that cannot be overloaded in C++
- Some interesting facts about static member functions in C++
- Advanced C++ | Virtual Constructor
- Local Classes in C++
- Advanced C++ | Virtual Copy Constructor
- Pure Functions
- Default arguments and virtual function
- What happens when more restrictive access is given to a derived class method in C++?
- Can virtual functions be private in C++?
- Virtual Functions and Runtime Polymorphism in C++ | Set 1 (Introduction)
- Can virtual functions be inlined?