By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,434 Members | 1,878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,434 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
"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

P: n/a
* 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.