473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Inheritance of objects within objects

I want to do something along these lines, but with one crucial
difference:

class foo1
{
public:
foo1(void){}
void Test1(void)
{
i1 = 1;
}
protected:
struct b1
{
int i1;
} bar;
};

class foo2:public foo1
{
public:
foo2(void){}
void Test2(void)
{
i1 = 1;
i2 = 2;
}
protected:
struct b2:public b1
{
int i2;
} bar;
};

In the above, there are two instances of bar - foo1::bar and foo2::bar.
I want to do something similar, but with only one instance of bar.

In other words I want foo2 to inherit from and extend the functionality
of foo1, and I want foo2 to contain an extended bar.

So foo1::Test1 would be accessing foo1::bar.i1 and so would foo2::Test2.

I'm fairly sure that this can't be done, but perhaps some of the more
experienced developers here know something I don't!
--
Simon Elliott http://www.ctsn.co.uk
Jul 22 '05 #1
2 1018
"Simon Elliott" <Simon at ctsn.co.uk> wrote:
I want to do something along these lines, but with one crucial
difference:

class foo1
{
public:
foo1(void){}
void Test1(void)
{
i1 = 1;
}
protected:
struct b1
{
int i1;
} bar;
};

class foo2:public foo1
{
public:
foo2(void){}
void Test2(void)
{
i1 = 1;
i2 = 2;
}
protected:
struct b2:public b1
{
int i2;
} bar;
};

In the above, there are two instances of bar - foo1::bar and foo2::bar.
I want to do something similar, but with only one instance of bar.

In other words I want foo2 to inherit from and extend the functionality
of foo1, and I want foo2 to contain an extended bar.

So foo1::Test1 would be accessing foo1::bar.i1 and so would foo2::Test2.

I'm fairly sure that this can't be done, but perhaps some of the more
experienced developers here know something I don't!


I don't think either that this can be done. What you could do is make foo1
into a foo_base class from which foo1 and foo2 are derived. Then foo1 can
contain an instance of the foo_base version of your nestest struct, and
foo2 can derive from it and contain an instance of that derived struct.

Jul 22 '05 #2
On 10/12/2004, Rolf Magnus wrote:
I don't think either that this can be done. What you could do is make
foo1 into a foo_base class from which foo1 and foo2 are derived. Then
foo1 can contain an instance of the foo_base version of your nestest
struct, and foo2 can derive from it and contain an instance of that
derived struct.


I'm always amazed at the fast response I get from this group. Thanks
for the suggestion: it's probably as close as I can get to my original
requirement.

--
Simon Elliott http://www.ctsn.co.uk
Jul 22 '05 #3

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

Similar topics

3
by: Joe Delphi | last post by:
Does Visual Basic support multiple inheritance? That is one child class inheriting from more than one parent class. JD
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...
0
by: Bita-kookoo | last post by:
I am having a problem with inheritance for my web solution. Here are the steps I took for a project within C#: -I first created a new class, descended from System.Web.UI.Page. For this...
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...
29
by: MAHESH MANDHARE | last post by:
Hi , Can Anyone explain me exactly why multiple inheritance not used in java and c# thanks, Mahesh -- Have A Good Day, Mahesh, Maheshmandhare@yahoo.co.in
3
by: Chris Kennedy | last post by:
What's the difference between importing a namespaces and inheriting.
10
by: John | last post by:
Hi, How can I achieve that a childs constructor is only callable from it's parent? Must I declare the class Private within A? Thanks in Advance Public MustInherit Class A Protected Sub...
31
by: John W. Kennedy | last post by:
I quite understand about prototypes and not having classes as such, but I happen to have a problem involving blatant is-a relationships, such that inheritance is the bloody obvious way to go. I can...
47
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
36
by: Pacific Fox | last post by:
Hi all, haven't posted to this group before, but got an issue I can't work out... and hoping to get some help here ;-) I've got a base object that works fine with named arguments when called...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
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
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...
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,...

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.