We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Class Children (Read 413 times)
Class Children
Apr 23rd, 2006, 6:55am
 
Hello,

I am currious wether there is a way for classes constructed within another class to access variables held within the class that it is constructed within. For example, I need a class to hold dynamic variables that other classes can access and change, without creating duplicates of that variable within itself and returning back and forth. Mainly becuase the variavle i want to store and change are massive arrays.

Can anyone suggest a neat method that does not involve using the instant name of the parent class.

cheers,
Benjamin
Re: Class Children
Reply #1 - Apr 23rd, 2006, 1:23pm
 
If the child class is actually defined as a child class, it can just access it's parent's variables at will.

e.g. Quote:
class top
{
 String a;
 child b;
 top()
 {
   a="top";
   b=new child();
 }
 
 void print()
 {
   b.print();
 }

 class child
 {
   child()
   {
   }
   
   void print()
   {
     println(a);
   }
 }
}

void setup()
{
 size(200,200);
 top a=new top();
 a.print();
}
Re: Class Children
Reply #2 - Apr 24th, 2006, 10:08am
 
Thanks. Shortly after posting my quiry I found the answer in the java documentation. We have been spoiled with Tabs in processing so whenever I define a new class I start a new Tab. Thank you for your help.

Benjamin
Page Index Toggle Pages: 1