R
relient
I'm learning about the virtual table in association with virtual
methods. I got most of the logic and understanding down (I believe) for
when you use 'override' and no 'override' or no 'new' modifier. What
I'm trying to figure out now is what happens when you do use modifier
'new' on a derived class method inherited from the base class?
My understanding for the override mechanism with the following code:
class Base
{
public virtual void Method( )
{
}
}
class Derived : Base
{
public override void Method( )
{
}
}
...is that the vtable will replace the Base.Method() address by making
the slot in the array of pointers (where Base.Method resides) point to
the new override method declared in the Derived class. Correct?
My understanding for when you do not 'override' or 'new' the base
method in the derived class is this: The vtable will not change where
the Base.Method address resides in the the slot in the array of
pointers, of the vtable, so, we'll be using the same base method. Yes?
Now to my main question: what happens when you do use the 'new'
modifier on the derived method? How will the vtable look?
Thanks in advance.
methods. I got most of the logic and understanding down (I believe) for
when you use 'override' and no 'override' or no 'new' modifier. What
I'm trying to figure out now is what happens when you do use modifier
'new' on a derived class method inherited from the base class?
My understanding for the override mechanism with the following code:
class Base
{
public virtual void Method( )
{
}
}
class Derived : Base
{
public override void Method( )
{
}
}
...is that the vtable will replace the Base.Method() address by making
the slot in the array of pointers (where Base.Method resides) point to
the new override method declared in the Derived class. Correct?
My understanding for when you do not 'override' or 'new' the base
method in the derived class is this: The vtable will not change where
the Base.Method address resides in the the slot in the array of
pointers, of the vtable, so, we'll be using the same base method. Yes?
Now to my main question: what happens when you do use the 'new'
modifier on the derived method? How will the vtable look?
Thanks in advance.