Welcome to WebmasterServe!

FREE TO JOIN! Join us now to engage in informative and friendly discussions about Webmastering, SEO, SEM, Internet Marketing, Programming, Graphic Design, Online Jobs and more. What are you waiting for? Ready to join our friendly community? It takes just one minute to register.

Dismiss Notice

Join WebmasterServe Forums 
Join the discussion! Have a better idea or an opinion? It takes just one minute to register Click Here to Join

My 2 Cents Virtual Base Class

Discussion in 'General Programming Discussions' started by Swati Mishra, Mar 16, 2016.

  1. Swati Mishra

    Yellow Belt

    Joined:
    Dec 28, 2015
    Messages:
    644
    Ratings:
    +105 / -0
    The concept of virtual base class is to have only one copy of the base class member in memory.
    Inheriting a class more than once through multiple paths create multiple copies of base class members in the memory. Thus, by declaring the base class inheritance is virtual, only one copy of the base class is inherited. A base class inheritance can be specified as virtual by using the virtual qualifier.
    Syntax

    Class A
    {
    ….
    }
    Class B : virtual public A
    {
    ……
    }
    Class C : virtual public A
    {

    }
    Classes B and C use the virtual keyword to inherit class A, so the class A is the virtual base class
     

Share This Page