473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1720
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sunil Menon | last post by:
Dear All, A class having no member variables and only a method sizeof(object) will return 1byte in ANSI and two bytes in Unicode. I have the answer for this of how in works in ANSI. But I don't...
6
by: RainBow | last post by:
Greetings!! I introduced the so-called "thin-template" pattern for controlling the code bloat caused due to template usage. However, one of the functions in the template happens to be virtual...
17
by: romixnews | last post by:
Hi, I'm facing the problem of analyzing a memory allocation dynamic and object creation dynamics of a very big C++ application with a goal of optimizing its performance and eventually also...
3
by: Pravesh | last post by:
Hello All, I had some query regarding virtual functions/destructors. If a class is having some/all of its methods that are virtual then is it recommended that it should also have virtual...
4
by: cantatahost | last post by:
Hello, Likely this has been asked before... We have a library (in DLL form) that we distribute. The interface to the library is all C, but within the library it uses C++ in many places. ...
11
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the...
1
by: steve | last post by:
Hello ! I have a special need implementing a lexical parser. I have a C restricted grammar, in which I accept such operations as (3<3.5) or (s<"string"). My problem is that I meet some...
17
by: Jess | last post by:
Hello, If I have a class that has virtual but non-pure declarations, like class A{ virtual void f(); }; Then is A still an abstract class? Do I have to have "virtual void f() = 0;"...
16
by: Stefano Sabatini | last post by:
Hi all, I'm facing this design problem. I have a table which defines the behaviour of an Object in a given state according to the type of event it is receiving. So for each couple...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.