testApp reference from other classes


I believe this may be already discuss, but my search didn’t get me to anything conclusive, so I post.

Basically I am trying to understand how you guys manage to comunicate data between cleasses and testApp, If I include a class in another class I have no problems referencing them and calling methods and variables, but if I include testApp.h in a class I get lots of errors and the app wont compile.

Also ofGetAppPrt() only reference a few methods and attributes but no custom methods and variables.

Any help will be much appreciated!


from a .cpp file, for example, “particle.cpp” you can do two things:

a) include “testApp.h” (so you know what’s inside the testApp)

b) cast the ofGetAppPtr as a testApp ptr

you can’t include testApp.h inside another .h file, as you would recursive includes (ie, testApp includes particle, particle includes testApp), but putting it in the .cpp is fine.

for example

#include "particle.h"  
#include "testApp.h"  
void particle::update(){  
   ((testApp*) ofGetAppPtr())->someVariableThatsInTestApp  = 100;  

I hope that helps

take care,

Hi zack,

Crystal clear, I am still new to the language so is still very unclear where to include the .h files. So I dont know the difference and implications of doing it in the header file or in the .cpp file, any chance for a bit of explanation?

Of course know I am aware of the recursive problem so that is easy to prevent, but is there any other reasons I need to be aware of?

Many thanks

Well I didnt got it working at the end I forgot to do the include, I am using ofxiPhone and if I include the testApp.h in the class I get lots of errors (about 7484 and 18 warnings)

In the Cannon.cpp I have

#include "Cannon.h"  
#include "testApp.h"  

and in the Cannon.h I have

#include "ofMain.h"  
#include "ofxBox2d.h"  
#include "ofxVec2f.h"  

If I remove the testApp.h include everything works fine, I have not done any else apart from that, any help will be much appreciated


Got it! I rename the Cannon.cpp to Cannon.mm and is working fine!