469,592 Members | 1,670 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

Different ways of implementing virtual functions by a C++ compiler.

Hi,

What are the different ways in which a virtual function can be
implemented by the C++ compiler? I know VTABLE and VPOINTER is only one
of the way. What are the other ways? What are the pros and cons of
these different ways? Why is VTABLE and VPOINTER method, the most
preffered method?

Thanks,
Chetan Raj
PS: I know that these questions would have been asked earlier in the
group, but my search led to ways in which a programmer should or should
not implement vitrtual function in the derived class. If you can give
me pointer to the source where this is already discussed, it wil be
helpful.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Nov 22 '05 #1
2 1603
"Chetan Raj" writes:
What are the different ways in which a virtual function can be
implemented by the C++ compiler? I know VTABLE and VPOINTER is only one
of the way. What are the other ways? What are the pros and cons of
these different ways? Why is VTABLE and VPOINTER method, the most
preffered method?

Thanks,
Chetan Raj
PS: I know that these questions would have been asked earlier in the
group, but my search led to ways in which a programmer should or should
not implement vitrtual function in the derived class. If you can give
me pointer to the source where this is already discussed, it wil be
helpful.


I suggest you post to comp.compilers, it is active. This group is not about
"How to write a compiler".
Nov 22 '05 #2
* Chetan Raj:

What are the different ways in which a virtual function can be
implemented by the C++ compiler? I know VTABLE and VPOINTER is only one
of the way. What are the other ways?
Here's one way you can think of a virtual function call in the context
of single inheritance (each class inherits at most from one base class,
which in turn, and so on):

first, if the class that is the object's dynamic type has an
implementation of that function, that implementation is executed;
otherwise, the same check is performed on that class' base class, and
so on.

That's suggests an obvious implementation strategy, which IIRC was
actually used by Borland's C++ compiler for a language extension used to
designate Windows window message event handlers.

It was also how virtual function call ("method calls") were originally
described and sometimes implemented in the Smalltalk language.

What are the pros and cons of
these different ways?
Memory, execution speed, flexibility.

Why is VTABLE and VPOINTER method, the most preffered method?


It works well in practice. ;-)

No, that's not a tongue-in-cheek answer.

It's the literal truth.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Sunil Menon | last post: by
16 posts views Thread by Stefano Sabatini | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.