Abstract base class with pure virtual functions

A

Arne Schmitz

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
 
G

Grizlyk

Arne said:
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?
 
V

Victor Bazarov

Arne said:
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
 
A

Arne Schmitz

Victor said:
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
 
D

Daniel Albuschat

Arne said:
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() {
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top