Connecting Tech Pros Worldwide Forums | Help | Site Map

Abstract base class with pure virtual functions

Arne Schmitz
Guest
 
Posts: n/a
#1: Jan 17 '07
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/ ---]

Grizlyk
Guest
 
Posts: n/a
#2: Jan 17 '07

re: Abstract base class with pure virtual functions


Arne Schmitz wrote:
Quote:
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?

Victor Bazarov
Guest
 
Posts: n/a
#3: Jan 17 '07

re: Abstract base class with pure virtual functions


Arne Schmitz wrote:
Quote:
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


Arne Schmitz
Guest
 
Posts: n/a
#4: Jan 17 '07

re: Abstract base class with pure virtual functions


Victor Bazarov wrote:
Quote:
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/ ---]
Daniel Albuschat
Guest
 
Posts: n/a
#5: Jan 17 '07

re: Abstract base class with pure virtual functions


Arne Schmitz wrote:
Quote:
Victor Bazarov wrote:
>
Quote:
>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() {
}
Closed Thread