473,503 Members | 1,696 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%cgl%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 1763
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******@hotmail.com> schrieb im Newsbeitrag
news:4b*************@individual.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******@hotmail.com> schrieb im Newsbeitrag
news:4b*************@individual.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******@hotmail.com> schrieb im Newsbeitrag
news:4b*************@individual.net...
Gernot Frisch wrote:
"Ian Collins" <ia******@hotmail.com> schrieb im Newsbeitrag
news:4b*************@individual.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******@hotmail.com> schrieb im Newsbeitrag
news:4b*************@individual.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
2033
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...
5
2974
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...
2
2153
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...
12
5386
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...
2
1472
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...
2
2177
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...
16
1640
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....
1
1623
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...
7
2368
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...
0
7083
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
7278
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
7328
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...
1
6988
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
7456
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
5578
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
4672
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
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
379
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...

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.