polymorphism - Virtual keyword use in C++ -


i understand c++ implements runtime polymorphism thorugh virtual functions , virtual keyword inherited don't see use of virtual keyword in derived class.

e.g. in below case if dropped virtual keyword in derived class still ptr->method() call goes derived::method. virtual keyword doing in derived class?

#include<iostream>  using namespace std;  class base { public:     virtual void method()     {         std::cout << std::endl << "base" << std::endl;     } };  class derived: public base { public:     virtual void method()     {         std::cout << std::endl << "derived" << std::endl;     } };  int main() {     base* ptr = new derived();     ptr->method();     return 9; } 

nothing. remind functions virtual or not.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -