Virtual functions

This thread contains 1 reply, has 2 voices, and was last updated by Nitesh User Do not delete 1 year, 12 months ago.

  • Author Replies
    • #52555

      What are virtual functions?

    • #52558

      A virtual function is a member function which is declared within the base class and is re-defined (Override) by the derived class. When you allude to a derived class object utilizing a pointer or a reference to the base class, you can call a virtual function for that object and execute the derived class’s version of the function.

      Following things are important to compose a C++ program with runtime polymorphism (utilization of virtual capacities)

      1) A base class and a derived class.
      2) A function with the same name in base class and derived class.
      3) A pointer or reference of base class type pointing or referring to an object of derived class.

      EXAMPLE: –

      using namespace std;

      class Base {
      virtual void show() { cout<<” In Base \n”; }

      class Derived: public Base {
      void show() { cout<<“In Derived \n”; }

      int main(void) {
      Base *xy = new Derived;
      xy->show(); // RUN-TIME POLYMORPHISM
      return 0;

      Output: In Derived

      Nitesh Bavishiya

Viewing 1 reply thread

You must be to reply to this thread.Please or . Registration is 100% free.


Call Us Now For Free Consultation97370 05566

Our experts listen to you patiently and suggest you the right course after conducting a personality profile test. Register your interest below to schedule personality profile test for you.


Contact Us

Working Hours

  • Monday9:00 AM – 9:00 PM
  • Tuesday9:00 AM – 9:00 PM
  • Wednesday9:00 AM – 9:00 PM
  • Thursday9:00 AM – 9:00 PM
  • Friday9:00 AM – 9:00 PM
  • Saturday9:00 AM – 9:00 PM
  • SundayClosed
Copyright 2016-2020 Smart Mentors. All Rights Reserved.



Sign up now to Become An Instructor

    Register your Interest