What is a virtual function?

devquora
devquora

Posted On: Feb 22, 2018

 

A virtual function is a method, which is used to replace the implementation provided by the base class. The said replacement is always called whenever the object in question is actually of the derived class, even if a base pointer instead of a derived pointer accesses the object. Virtual functions are always used with inheritance, and they are called according to the type of the object pointed or referred, not according to the type of pointer or reference. In other words, virtual functions are resolved later than usual, at runtime. The keyword virtual is used to make a method virtual.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    C++ Interview Questions

    Explain what is OOP?

    Object-oriented programming (OOP) is a type of computer programming, also more commonly known as software design, in wh..

    C++ Interview Questions

    What is the difference between #import and #include in C++?

    The statement #include is used in C++ to include the source file or import the header files containing definitions of f..

    C++ Interview Questions

    What is ‘this’ pointer?

    The ‘this’ pointer is passed as a hidden argument to all the non-static member method calls and is available as a l..