471,330 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

virtual table; override; new, question

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.

Feb 17 '06 #1
1 5655
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?
Right. The method in the derived class will get its own vtable slot.

Now to my main question: what happens when you do use the 'new'
modifier on the derived method? How will the vtable look?


The same thing as when you don't specify new or override. The only
difference is that you get a compiler warning if you don't specify
anything.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 17 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

32 posts views Thread by Adrian Herscu | last post: by
4 posts views Thread by Rafael Veronezi | last post: by
11 posts views Thread by z_learning_tester | last post: by
15 posts views Thread by John Salerno | last post: by
14 posts views Thread by Bruno van Dooren | last post: by
reply views Thread by relient | last post: by
5 posts views Thread by Marcel Hug | last post: by
4 posts views Thread by David Zha0 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.