472,119 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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 1652
"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
reply views Thread by leo001 | 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.