473,386 Members | 1,758 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,386 software developers and data experts.

Abstract base class with pure virtual functions

If i have an abstract base class, that only contains pure virtual methods
(and maybe some non-virtual methods), is a vtable still being generated,
for the first derived class that implements those pure virtuals? My idea is
that as long as there are less than two virtual methods of the same name in
existance, it would (in theory) not be necessary to build a vtable, thus
eliminating the need for a lookup during runtime.

Arne

--
[--- PGP key FD05BED7 --- http://www.root42.de/ ---]
Jan 17 '07 #1
4 1697
Arne Schmitz wrote:
If i have an abstract base class, that only contains pure virtual methods
(and maybe some non-virtual methods), is a vtable still being generated,
for the first derived class that implements those pure virtuals? My idea is
that as long as there are less than two virtual methods of the same name in
existance, it would (in theory) not be necessary to build a vtable, thus
eliminating the need for a lookup during runtime.
And how are you going to call the Single virtual member via pointer to
its base class?

Jan 17 '07 #2
Arne Schmitz wrote:
If i have an abstract base class, that only contains pure virtual
methods (and maybe some non-virtual methods), is a vtable still being
generated, for the first derived class that implements those pure
virtuals? My idea is that as long as there are less than two virtual
methods of the same name in existance, it would (in theory) not be
necessary to build a vtable, thus eliminating the need for a lookup
during runtime.
"Less than two virtual method of the same name in existance"? Could
you please elaborate? The 'vtable' method of implementing virtual
function mechanism has nothing to do with the number of identically
named functions in existence. Besides, if I derive from your class
and override one of them, and then do it again, and again, how (or
why) would it affect the way _your_ class is implemented?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 17 '07 #3
Victor Bazarov wrote:
The 'vtable' method of implementing virtual
function mechanism has nothing to do with the number of identically
named functions in existence.
Yes, I just realised that virtual member functions are implementation
dependent. This and your other comment answered my question. :)

Thanks,

Arne

--
[--- PGP key FD05BED7 --- http://www.root42.de/ ---]
Jan 17 '07 #4
Arne Schmitz wrote:
Victor Bazarov wrote:
>The 'vtable' method of implementing virtual
function mechanism has nothing to do with the number of identically
named functions in existence.

Yes, I just realised that virtual member functions are implementation
dependent. This and your other comment answered my question. :)
You should still implement a (pure) virtual dtor.
Note that even if it's abstract, you still need to provide a dtor
definition.

e.g.

Having this in your header:

class abstract {
virtual void foo() = 0;
virtual ~abstract() = 0;
};

Put this in your implementation file:

abstract::~abstract() {
}
Jan 17 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Merlin | last post by:
Hi Been reading the GOF book and started to make the distinction between Class and Interface inheritance. One question though: Do pure abstract classes have representations? (data members?)...
4
by: Tony Johansson | last post by:
Hello! Assume you have an abstract class called Body and a derived class called cylinder. When you have an abstract class you can't instansiate an object. As you can see in the abstract class...
4
by: WittyGuy | last post by:
Hi all, Though I know the concepts of both abstract class & virtual function (like derived class pointer pointing to base class...then calling the function with the pointer...), what is the real...
8
by: Dev | last post by:
Hello, Why an Abstract Base Class cannot be instantiated ? Does anybody know of the object construction internals ? What is the missing information that prevents the construction ? TIA....
12
by: placid | last post by:
Hi if a have the following classes class A { public: A(); virtual ~A(); virtual string someFunction() const = 0;
22
by: ypjofficial | last post by:
Hello All, I have following doubt.. class abstractclass { public: abstractclass(){} virtual void method()=0; };
4
by: sudhir | last post by:
Q 1. I defined a class with 10 functions . It contains declaration of 5 functions and 5 functions are declared and defined. Is this class is said to a abstract class ? Q 2. Which one is...
6
by: Alden Pierre | last post by:
Hello, http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.7 As per the link above it's wise to have a virtual deconstructor when creating an abstract class. Here is when I'm...
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;"...
6
by: Miguel Guedes | last post by:
Hello, I recently read an interview with Bjarne Stroustrup in which he says that pure abstract classes should *not* contain any data. However, I have found that at times situations are when it...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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.