Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Abstract base class with pure virtual functions (http://www.velocityreviews.com/forums/t459874-abstract-base-class-with-pure-virtual-functions.html)

Arne Schmitz 01-17-2007 02:47 PM

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/ ---]

Grizlyk 01-17-2007 02:57 PM

Re: Abstract base class with pure virtual functions
 
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?


Victor Bazarov 01-17-2007 02:59 PM

Re: Abstract base class with pure virtual functions
 
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



Arne Schmitz 01-17-2007 03:10 PM

Re: Abstract base class with pure virtual functions
 
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/ ---]

Daniel Albuschat 01-17-2007 06:16 PM

Re: Abstract base class with pure virtual functions
 
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() {
}


All times are GMT. The time now is 10:12 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.