473,657 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1717
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::~abst ract() {
}
Jan 17 '07 #5

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

Similar topics

16
3515
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?) What about abstract classes? Should abstract classes have a destructor and or constructor? What about pure abstract classes?
4
2307
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 there are one data member called density that you can't access because there will not be any object of class Body. The data member density will be inheritated and all the member functions. So when you have an instance of class Cylinder and you...
4
4203
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 implementation usage of these concepts? Where these concepts will be used. Please provide some illustration (real-time), so that it can be easily comprehended. Thanks, wittyGuy
8
21716
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. Dev
12
21222
by: placid | last post by:
Hi if a have the following classes class A { public: A(); virtual ~A(); virtual string someFunction() const = 0;
22
2390
by: ypjofficial | last post by:
Hello All, I have following doubt.. class abstractclass { public: abstractclass(){} virtual void method()=0; };
4
2338
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 correct? If a class contains a virtual class then it is said to a abstract class ? Or a abstract class always contains a virtual function ?
6
3131
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 little confused. Am I deleting the right object when I call the virtual deconstructor? I was under impression when creating a class if I'm not specifically allocating memory, do not implement deconstructor and let the default take care of it...
17
3526
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;" instead? I think declaring a function as "=0" is the same
6
4023
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 would be useful to have /some/ data defined in such an abstract class for reasons of forming a common block of data existing in or used by all descendant classes (see example below.) In such a case where a common block of data *always* exists,...
0
8399
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8312
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8606
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4159
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.