Virtual Class in C++

Last session we have discussed the overloading ok and next one overriding concept like this now today I am going to start about virtual classes but I have used at the virtual function in dynamic binding location of discussion about the dynamic binding which is working based on virtual function ok now today we are going to discuss about virtual class what is called virtual class and when we have to make it virtual ok you wait make a class as virtual when we have to make a class virtual OK you know that you’re having five different types of inheritance ok in C plus plus we are working with five types of inheritance models single level multilevel multiple hierarchical hybrid or multipath inheritance in multiple inheritance what happened ok generally multiple inheritance means what we are creating a class from more than one base class we are creating a class from more than one ok next what is called hierarchical inheritance where creating several classes from one base class for example there is a situation like this ok now it is one of the base class just saying it is the base class now from this base class there is situation I have to declare two classes ok derived and derived ok for example this base class name is a derived class name is be and this derived class in CSS am right now what happened in hierarchical inheritance the base class properties are password to driver for example here one function is there suppose function is there now it is derived from this class ok this class also derived from this class now what happened this function is password to this means here function is there and same function passed to this one also that’s why I hear one more function is the letter there is a situation where we have to define one more class from these two classes now there is a situation suppose I want to define another derived class suppose it is the new derived class D OK it is office base class from the base class there is two derived class is called B and C now from B.Ed how to derive the now what happened watch it already derived class is having one function actually this function is a member of base class and here also one function is there it is a member of base class now this function past and this function is fast indirectly the meaning is what now these are created from in these two derived from one base class ok that means that having one base class that means already base class properties are one time here and second time here now we are creating the next derived from these two derived that means already disturbing base class property base class property know the derived is created to time from the same base class that means in this class creation what happened function one already one time here is a function was already here or not note 2 copies of past and that means what happened here the same class is created two times from the base class ok but actually inheritance doesn’t support this concept because of we are not able to create one class more than one time by using the same base class to get inheritance OK what happened where passing the base class properties to the derived class but in this example what happened we are passing the base class properties to x to the derived class that means two copies of base class members are created in derived class now actually it is not possible OK nothing is it is not possible and it gives errors now how to solve this issue ok now to solve this issue just you have to make it work jewel whenever you want to make ok this kind of inheritance then go for ok virtual now it is called virtual class base base class will become virtual whenever the class is virtual what happened means the class properties are bypass and only one set of properties are available in derived class ok that’s why we can’t create one derived class from more than more than one time from the same base class to avoid this problem what we have to do means we have to create the derived class by using virtual keyword that means when class B is created make it virtual and when class is created make it virtual letter create the class day now the problem is solved now I am going for implementation concept ok now I am going to conduct an example on virtual class ok that’s why I hear you should have to make base class virtual that’s why sometime you might how to make the base class virtual like in this situation ok now implementation project ok, Noida hash include iostream dot has next hash include on your daughter age 140 scene another one clrscr and get Ch ok now there is a class suppose class name is C1 ok now I am going to create a base class like this favour and here there is only one function I want to maintain public void say one function means no easy for understand it is C1 class function ok here see out C1 class function ok slash and handle what it may be know the class complete ok now it is the base class in this example 7 is the base class because of I want to drive a class from this river ok now I am going to create another class C2 Ok actually it is a class c to now it is derived from public ok see you that means the same class is created from C1 class ok now here once again public in public John White C2 function ok now it is AC to function and here the contents C2 class function / another function close class also close ok in the situation what happened C2 class is derived from fever in which word public mode already in public section which one is AC one function that makes it is fast to say to crash out now there is another class class C3 Public C1 hear what should say when is the base class and C2 is the derived class and in this situation also see one is the day

Speak Your Mind

*