Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Abstract base class with pure virtual functions

Reply
Thread Tools

Abstract base class with pure virtual functions

 
 
Arne Schmitz
Guest
Posts: n/a
 
      01-17-2007
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/ ---]
 
Reply With Quote
 
 
 
 
Grizlyk
Guest
Posts: n/a
 
      01-17-2007
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?

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-17-2007
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


 
Reply With Quote
 
Arne Schmitz
Guest
Posts: n/a
 
      01-17-2007
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/ ---]
 
Reply With Quote
 
Daniel Albuschat
Guest
Posts: n/a
 
      01-17-2007
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() {
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pure virtual functions: declaring a function in a base class Martin C++ 5 08-26-2010 09:52 AM
private virtual functions and pure virtual functions with bodies John Goche C++ 10 12-08-2006 04:00 PM
what is the difference between abstract class and pure abstract class? skishorev@yahoo.co.in C++ 4 05-17-2006 08:07 AM
Can abstract base class have V-table?, Will the pointer to virtual destructor be entered into the virtual table? sojin C++ 12 04-07-2006 09:02 AM
paradox when constructor of an pure abstract base class called? ypjofficial@indiatimes.com C++ 22 01-24-2006 01:41 AM



Advertisments