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.
IndexProgramming Questions & HelpSyntax Questions › forward references in classes
Page Index Toggle Pages: 1
forward references in classes (Read 385 times)
forward references in classes
Mar 11th, 2008, 10:43pm
 
Hi There, sorry if this is a FAQ. Is there a way to fix circular class definitions?

class A {
 B b;
}
class B {
 A a;
}

makes Processing complain that it doesn't find Type B.
I've got plenty of such small classes in my source, which I'd hate
to split in as many source files.

Re: forward references in classes
Reply #1 - Mar 12th, 2008, 12:31am
 
Try using Eclipse IDE (see Integration forums).

link: http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Integrate;action=display;num=1117133941

Not to say that future versions of the processing IDE might not surpass eclipse's features, but eclipse has a reputation for being right awesome.
Re: forward references in classes
Reply #2 - Mar 12th, 2008, 8:01am
 
or add .java to the name of the tab (can't be the main one, though), which will circumvent the preprocessor (see help -> getting started for more about tabs).
Re: forward references in classes
Reply #3 - Mar 13th, 2008, 2:32am
 
fry wrote on Mar 12th, 2008, 8:01am:
or add .java to the name of the tab (can't be the main one, though), which will circumvent the preprocessor (see help -> getting started for more about tabs).


So I tried that but I'm hitting the problem of external classes (in the .java tabs) not finding core functions. I understand I can either:
- write everything as: processing.core.PApplet.sin(p*processing.core.PConstants.TWO_PI / x)
- or pass PApplet to all the subclasses as a parameter to the each constructor

Is there a simpler way

Re: forward references in classes
Reply #4 - Mar 14th, 2008, 12:09am
 
I found what I was doing wrong: my pde didn't have any setup/draw functions, and therefore, when transformed to Java, the whole code (including the class declarations) was included into setup(). And in this context, classes can't forward reference. Re-adding the functions at the bottom works.

(Although the answers to my original question misled me into investigating splitting my code into files (only because I hadn't explained well), it wasn't a waste of time, as I've now realised that if your hack has more than one sourve file it's not possible to do much without ditching the PDE and going full-Java instead.)
Page Index Toggle Pages: 1