Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Calling a parents function from a child class?

Author
Message
_Pauli_
AGK Developer
14
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 20th May 2010 18:58
This is more like C++ question than DarkGDK but I guess it fits here anyway.

So how do I call a function of a parent class from one of its childrens classes?

Example:

The child class:



Now the parent class:



So let's say I want to call ParentA.FunctionA() from within ChildA.ChildFunction().

1) How would I do this?

2) Is it possible to call ChildB.ChildFunction() from ChildA.ChildFunction()?

Thanks in advance!

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
Ultimate_H
15
Years of Service
User Offline
Joined: 11th Mar 2009
Location: A place that is neither here nor there
Posted: 20th May 2010 19:26
I believe I posted some code that did just this kind of think earlier. Basically, you define the ChildFunction() after the parent object has been created (ie: cParent p). so it would look something like this:



this hasn't been tested in the case of the child being owned by the parent, but has been tested where the calling class is above the called class.

Hope that's what your looking for
-H

_Pauli_
AGK Developer
14
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 20th May 2010 19:40
Ok, thanks.
Unfortunatly that's not exactly what I'm looking for...

Of course the Child (in your example) can access p.ParentFunction() since it has been created before in the global scope.

In my case, the child doesn't "know" about its parent, except that it was created from it. Sounds strange, not sure if that is even possible in C++...

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 20th May 2010 20:32
Have the Child hold a pointer to the parent; ie:



Then your child class can access m_Parent->FunctionA() just as you need...

JTK
_Pauli_
AGK Developer
14
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 20th May 2010 22:21
Ah cool, thanks!
I thought about something along those lines...
I'm going to try it later.

By the way, is protected the same as private?

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 20th May 2010 22:28
Not quite. private is private. Mine. No-one else even knows about it; protected is a little bit more relaxed in that it's mine, but if you inherit from me, I'll share with you...

JTK

Login to post a reply

Server time is: 2024-07-07 01:06:17
Your offset time is: 2024-07-07 01:06:17