Reference parent object of child object?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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();
parent.CreateObject2() // object1 creates a new object called object2
object2.parent // I want to be able to refer back to the
parent from the newly created "child object"

or when I create object2 do I have to pass a reference to "parent" in order
to reference it from within object2.

Thanks,

Alex
 
Alex said:
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?

Yes. That's how you have to do it.


John Saunders
 
Back
Top