Wednesday, 15 September 2010

c++ - vptr - virtual tables -


There is nothing I do not know.

For every class, I declare that the vptr members pointing to the class virtual table is hidden.

Say I have this announcement:

  class support {virtual_table * vptr; // It's completely hidden, just stating the clear virtual zoo (foo); } Category is defined: Public base {virtual_table * vptr; / / That is also hidden in the virtual zoo foo (); Virtual zero thief (); }  

First I have to understand something, is it really the name of the member of VPTR for both derivative and base?

Second, what happens in this situation:

  base * original = new derivative ();  

I have found, the basic variable gets, VPTR is getting, but how is this happening? Generally, when a conversion occurs, then the derivative basic base (including the VPT of the base) must be assigned to the basic, and should not be derived vptr is probably different if both classes have a variable with the same name I do not know.

The third and final question: When I have

  base * basic = new derived ();  

Is there a way to call from a basic base even if it's virtual?

Thanks

First, yes, it is a single member. It is officially handed over for the first time when the base constructor is run, and the derivative constructor is assigned a second time while running. (In the case of the default blank constructs, the waste assignment of the base has been removed.)

Second, there is no actual conversion. Actually, the etymology can be given the name of the "one" relationship. In the case, the derivative "one is" basis if you consider the first bytes of the memory of the derived object, then they get the same meaning from the first bytes of the original object.

Third, you can call the basic member function as follows: basic- & gt; Base :: foo ();


No comments:

Post a Comment