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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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?
- Pure virtual destructor in C++
- Macros vs Functions
- fill() and fill_n() functions in C++ STL
- Return from void functions in C++
- Forward List in C++ | Set 1 (Introduction and Important Functions)