473,753 Members | 8,077 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple ineritance question

Hello!

I have s quick question regarding multiple ineritance that I hope that
someone will have the time to look at. I have the following classes that
I try to compile and use:

class A
{
public:
virtual void foo() = 0;
};

class B : public A
{
public:
virtual void bar() = 0;
};

class A_Impl : public A
{
public:
void foo() { }
};

class B_Impl : public A_Impl, public B
{
public:
void bar() { }
};

Now when I try to create an instance of B_Impl I get the following error
message when I try to compile with gcc:

main.cpp: In function `int main()':
main.cpp:7: cannot allocate an object of type `B_Impl'
main.cpp:7: because the following virtual functions are abstract:
A.h:7: virtual void A::foo()

Can anyone tell me why this is? Surely B_Impl has inerited A_Impl's
implementation of void foo()?

Regards,
Mattias

Jul 19 '05 #1
2 3840

Mattias B wrote:
...
I have s quick question regarding multiple ineritance that I hope that
someone will have the time to look at. I have the following classes that
I try to compile and use:

class A
{
public:
virtual void foo() = 0;
};

class B : public A
{
public:
virtual void bar() = 0;
};

class A_Impl : public A
{
public:
void foo() { }
};

class B_Impl : public A_Impl, public B
{
public:
void bar() { }
};

Now when I try to create an instance of B_Impl I get the following error
message when I try to compile with gcc:

main.cpp: In function `int main()':
main.cpp:7: cannot allocate an object of type `B_Impl'
main.cpp:7: because the following virtual functions are abstract:
A.h:7: virtual void A::foo()

Can anyone tell me why this is? Surely B_Impl has inerited A_Impl's
implementation of void foo()?
...


'B_Impl' has two subobjects of type 'A'. One comes through base class
subobject 'A_Impl', another - through base class subobject 'B'. Virtual
function 'foo' from the former has 'A_Impl::foo' as final overrider,
which is not pure. Virtual function 'foo' from the latter has 'A::foo'
as final overrider, which is _pure_. For this reason, as defined in
10.4/4 class 'B_Impl' is an abstract class and cannot be instantiated.

Provide a non-pure final overrider for all 'foo' functions is your class
'B_Impl' and the code will compile. If I understand your intent
correctly, you need something like this

class B_Impl : public A_Impl, public B
{
public:
void bar() {}
void foo() { A_Impl::foo(); }
};

You should probably also decide whether you really need two distinct
base class subobjects of type 'A' in 'B_Impl' and, maybe, use 'A' as
virtual base class.

--
Best regards,
Andrey Tarasevich
Brainbench C and C++ Programming MVP

Jul 19 '05 #2

"Mattias B" <br****@ludd.lu th.se> wrote in message
news:3f******** *************@n ews.luth.se...
Hello!

I have s quick question regarding multiple ineritance that I hope that
someone will have the time to look at. I have the following classes that
I try to compile and use:

class A
{
public:
virtual void foo() = 0;
};

class B : public A
{
public:
virtual void bar() = 0;
};

class A_Impl : public A
{
public:
void foo() { }
};

class B_Impl : public A_Impl, public B
{
public:
void bar() { }
};

Now when I try to create an instance of B_Impl I get the following error
message when I try to compile with gcc:

main.cpp: In function `int main()':
main.cpp:7: cannot allocate an object of type `B_Impl'
main.cpp:7: because the following virtual functions are abstract:
A.h:7: virtual void A::foo()

Can anyone tell me why this is? Surely B_Impl has inerited A_Impl's
implementation of void foo()?


Yes, but not B's. You're inheriting "doubly" from A. Based on the fact
that you're asking this question leads me to think that you probably
actually want virtual inheritance from A.
Jul 19 '05 #3

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

Similar topics

13
12051
by: jing_li | last post by:
Hi, you all, I am a newbee for php and I need your help. One of my coworker and I are both developing a webpage for our project using php. We have a copy of the same files in different location on the server (in our own accounts on the same machine). When I am testing both versions of our program using the same browser (IE on Windows or Konqueror on Linux) the session variables will mix up and only the latest selection or options will...
3
6113
by: DarthMacgyver | last post by:
Hello, I recently wrote a survey application. Each question is very similar. The first questions gives me a problem when there are multiple people taking the survey (The Database connection Timed out) I am using the Data Access Application Blocks as ASP.NET (using VB.NET) and SQL 2000. In there first question there can be up to 27 answers. So I figured instead of making 27 different trips to the database I woulc just concatenate my...
6
2839
by: Paul | last post by:
In real life situation, do we ever come across a situation where we would need two base objects in an object. A snippet is worth 1000 words (: so... class Base { }; class Derived1:public Base { };
22
23383
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete examples?
32
14887
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
9
23083
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated to a pool. If I assign only one application to a applicaton pool and have multiple worker processes assigned to that pool. Will my application be processed by many worker processes?
6
3990
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public string UID; public string PWD; }
35
9362
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from 500000 to 3200000 of a file whose size is say 20MB... how do i request a download which starts directly at 500000th byte... thank u cheers
7
15658
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is there an equivalent property for the DataGridView? I have searched, but have not found one. I would like the user to be able to see all the columns of the table on one screen - thus eliminating the need to use the horizontal scroll bar to view...
0
8896
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
9451
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
9421
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
6151
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4771
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
4942
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3395
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2872
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2284
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.