473,569 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reference to parent inherritance?

Is there any way to get a reference of parent class in default c'tor?

Like this:

class foo
{
class bar
{
foo& m_f;
public:
bar(const foo* f) : m_f(*f) {}
}
m_bar(this);
};

int main()
{
foo poo;
return 0;
}
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%c gl%ssic%ccom%c" , "ma", 58, 'g', 64, "ba", 46, 10);}

_______________ _______________ __________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
May 3 '06 #1
9 1776
Gernot Frisch wrote:
Is there any way to get a reference of parent class in default c'tor?

No. you have to be explicit in C++, unlike Java.

--
Ian Collins.
May 3 '06 #2

"Ian Collins" <ia******@hotma il.com> schrieb im Newsbeitrag
news:4b******** *****@individua l.net...
Gernot Frisch wrote:
Is there any way to get a reference of parent class in default
c'tor?

No. you have to be explicit in C++, unlike Java.


Don't know about java. I have a class "foo" that has a "helper-class"
"bar". It's just to bring somehierarchy in a large set of functions.
I'll guess I have to do it with a dynamical allocation of m_pBar the
c'tor of foo then.
Thank you,
-Gernot
May 3 '06 #3
Gernot Frisch wrote:
"Ian Collins" <ia******@hotma il.com> schrieb im Newsbeitrag
news:4b******** *****@individua l.net...
Gernot Frisch wrote:
Is there any way to get a reference of parent class in default
c'tor?


No. you have to be explicit in C++, unlike Java.

Don't know about java. I have a class "foo" that has a "helper-class"
"bar". It's just to bring somehierarchy in a large set of functions.
I'll guess I have to do it with a dynamical allocation of m_pBar the
c'tor of foo then.


I think adding a reference to the outer class is one of things proposed
for the next revision of the standard.

--
Ian Collins.
May 3 '06 #4

"Ian Collins" <ia******@hotma il.com> schrieb im Newsbeitrag
news:4b******** *****@individua l.net...
Gernot Frisch wrote:
"Ian Collins" <ia******@hotma il.com> schrieb im Newsbeitrag
news:4b******** *****@individua l.net...
Gernot Frisch wrote:

Is there any way to get a reference of parent class in default
c'tor?
No. you have to be explicit in C++, unlike Java.

Don't know about java. I have a class "foo" that has a
"helper-class"
"bar". It's just to bring somehierarchy in a large set of
functions.
I'll guess I have to do it with a dynamical allocation of m_pBar
the
c'tor of foo then.


I think adding a reference to the outer class is one of things
proposed
for the next revision of the standard.


Would be nice - but my life does not depend on it.
May 3 '06 #5

Ian Collins wrote:
Gernot Frisch wrote:
"Ian Collins" <ia******@hotma il.com> schrieb im Newsbeitrag
news:4b******** *****@individua l.net...
Gernot Frisch wrote:

Is there any way to get a reference of parent class in default
c'tor?
No. you have to be explicit in C++, unlike Java.

Don't know about java. I have a class "foo" that has a "helper-class"
"bar". It's just to bring somehierarchy in a large set of functions.
I'll guess I have to do it with a dynamical allocation of m_pBar the
c'tor of foo then.


I think adding a reference to the outer class is one of things proposed
for the next revision of the standard.

Certainly it is not. For one thing, an inner class could very well be
stand alone.

/Peter --
Ian Collins.


May 3 '06 #6
Gernot Frisch wrote:
Is there any way to get a reference of parent class in default c'tor?

Like this:

class foo
{
class bar
{
foo& m_f;
public:
bar(const foo* f) : m_f(*f) {}
}
m_bar(this);
};

int main()
{
foo poo;
return 0;
}


You nearly got it right.

class foo
{
class bar
{
foo & m_f;
public:
bar(foo & f) : m_f(f) {}
} m_bar;
public:
foo() : m_bar(*this) {}
};

My compiler, however, gives me a warning. See
[http://www.parashift.com/c++-faq-lit...html#faq-10.7].

--
Martin
May 3 '06 #7
You nearly got it right.

class foo
{
class bar
{
foo & m_f;
public:
bar(foo & f) : m_f(f) {}
} m_bar;
public:
foo() : m_bar(*this) {}
};


This is exaclty what I needed. Yeee-haaaaa!
May 3 '06 #8
peter koch wrote:
Ian Collins wrote:

I think adding a reference to the outer class is one of things proposed
for the next revision of the standard.


Certainly it is not. For one thing, an inner class could very well be
stand alone.

Sorry, too many dead brain cells.

I was thinking of granting a nested class access to its containing class
private members, which some compilers do as an extension.

--
Ian Collins.
May 3 '06 #9
Gernot Frisch wrote:
You nearly got it right.

class foo
{
class bar
{
foo & m_f;
public:
bar(foo & f) : m_f(f) {}
} m_bar;
public:
foo() : m_bar(*this) {}
};

This is exaclty what I needed. Yeee-haaaaa!

Sorry I gave you some wrong advice, I was answering "Is there any way to
get a reference of parent class in default c'tor?" and I didn't spot
that you had a non-default constructor in your example :)

--
Ian Collins.
May 3 '06 #10

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

Similar topics

1
2045
by: Alex | last post by:
Is there a way to reference the "parent" object that creates a child object from within the child object? Or do I have to pass a reference to the parent object to the constructor of the child object so that the child object "knows" who is creating it? ie: how would I do something like this: Object1 parent = new Object1();...
5
2984
by: JC | last post by:
hi all First of all, sorry for my (bad) english, I have a javascript: <script type="text/javascript"> <!-- function gointo(td,color){td.style.cursor='default';td.bgColor=color;} function gooutoff(td,color){td.style.cursor='default';td.bgColor=color;}
2
2159
by: Jim Red | last post by:
hello first of all, i know, there are no classes in javascript. but i will use that word for better understanding of my question. here we go. i have three classes and need a reference to the parent class. could this be done by a reference, or just by constructing the class. function Class1() { this.class2 = new Class2();
12
5392
by: marcadonis | last post by:
Hi! Does anybody know of a way that I can keep a reference to an object that I can then reuse? I tried various approaches using navigator, but these all fail in an iframe due to premission problems. For e.g.: navigator.stuff = 5;
2
1476
by: Sidorf | last post by:
Hi It's a little hard for me to explain my problem, but i'll try. I have an application in which i have a ManagerClass, many ClientClass-es ans some ControlClass. The ManagerClass creates one or more instances of ClientClass. ClientClass creates some controls from ControlClass. In the ControlClass i have derived some common control classes...
2
2185
by: Roy | last post by:
Ok, this is incredibly annoying. Below I have an ImageButton and it's ImageButton_Click sub. See the 6 response.writes? The output for them is displayed below in asterisks. Question: What part of the TemplateColumn below does sender.parent.parent.Cells(9) reference??? IOW, what tag does it reference? The templatecolumn is the 9th field in the...
16
1643
by: John | last post by:
Hi I have posted this question several times but have received no reply. I have a main form which contains a panel which in turn contains a child form, like this; MainForm->MyPanel->ChildForm. The question is; how can I, from the child form, get a reference to the main form? If I try to do dim frm as new mainform then I get reference to a...
1
1627
by: Brian P | last post by:
I have a class, Folder, that I want to hold a reference to its parent Folder as well as its subfolders. I'm using List<Folder> to hold its list of sub folders. What I want to do is when a folder is added to this list, automatically set the parent reference. But this seems impossible. It seems like I need to keep List<Folder> private...
7
2373
by: vunet | last post by:
I am still not clear about how to reference an object within another object to pass first object to a function: var Parent = { myFunc : function(){ alert("Parent = "+this) }, Child : { //how to get reference to Parent? myChildFunc : function(){
0
7917
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
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...
1
7665
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...
0
7962
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...
0
6277
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5501
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...
0
3651
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...
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
933
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...

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.