473,466 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Wierd Inheritance problem

Hello everyone,

I have this problem, I want to declare an interface class and have
it inherit from other interfaces. But when I define a concrete class I
want to substitute implementations of interfaces instead of the
interfaces themselves; In much the same way I can use a refrence to an
interface within a class but point to any object that implements that
interface.To illustrate:

class AInterface
{
public:
virtual char* something()=0;
}

class AImplementation
{
public:
char* something(){return "doing something...";};
}

class BInterface : public AInterface
{

}

Now the problem is, how do I inherit from BInterface but use
AImplementation instead of AInterface? I looked at late binding and
runtime inheritence but they don't seem to be what I want. Any pointers
to what I want to do?

The reason I don't want to just use concrete classes is that I don't
want to build a new set of classes every time I change platforms or
other external parts of my program. I'll just have to do
implementation\platform specific code on a few interfaces instead.

Thanks to all that apply.

p.s. I also posted this to comp.std.c++ but I did not cross post
because I don't think it's polite to cross post to a moderated and
unmoderated group.

Jul 23 '05 #1
2 1096
* br**********@personainternet.com:

class AInterface
{
public:
virtual char* something()=0;
}

class AImplementation
{
public:
char* something(){return "doing something...";};
}

class BInterface : public AInterface
{

}

Now the problem is, how do I inherit from BInterface but use
AImplementation instead of AInterface?


You can either implement the BInterface functions and forward to an instance
of AImplementation (with the code you've presented that's the only option
because AImplementation does not implement AInterface, but then, the lacking
semicolons make me suspect it's not more than a "kind-of-like" example), or
you can use virtual inheritance of interfaces:

class AInterface
{
public:
virtual char const* something() const=0;
};

class AImplementation: public virtual AInterface
{
public:
virtual char const* something() const{return "doing something...";};
};

class BInterface : public virtual AInterface
{
public:
virtual void foo() {}
};

class Client: public AImplementation, public virtual BInterface
{
};

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #2
Thanks,

The code you presented here is actually what I meant to write.
Thanks for reading between the lines. I tested what you gave me here
and this is exactly the behaviour I was looking for. So, now I'm going
to look through my books and learn about virtual inheritance. I've
never even heard of virtual inheritance before so I guess i'm starting
to use slightly advanced features. Anyways thanks again.

Jul 23 '05 #3

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

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
3
by: Markus Fischer | last post by:
Hi, I'm experiencing a wierd problem with IE 6 in Windows with two _slightly_ different Version. Give the following HTMl-Code, ideally the output of offsetTop should be "105"; a few pixel...
14
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
22
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...
2
by: CMEDIA_SOUND | last post by:
I have a peculiar problem, I have a tabpage with a label control on it. When i set a background image to the tabpage and drag the label around it has paint issues in that it is slow, granted the...
1
by: cody | last post by:
I have a OOP problem with the well known pattern where objects containing an object which represents a list of subobjects. Now my problem is that the ctor of a subobject indirectly calls the...
6
by: VR | last post by:
Hi, I read about Master Pages in ASP.Net 2.0 and after implementing some WinForms Visual Inheritance I tryed it with WebForms (let's say .aspx pages, my MasterPage does not have a form tag itself...
0
by: Michael | last post by:
Hi, I found a wierd problem in DataGrid. If I set DataGrid's DataSource to empDataSet1 at designtime, then I can never change its DataSource at runtime, e.g., in the Button1_Click event...
3
by: Leo Seccia | last post by:
Hello everyone, I have a c# project with a sql server database. I have a number of lookup tables in my database which I successfully managed to import into my LINQ dataclasses. eg. Table:...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...
0
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 ...

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.