Sharing variables between classes

Hi guys,

Firstly, I am an oF noob and have been having a hell of a time to pass variables from one class to another. I am trying to pass values from ClassTwo to ClassOne using a pointer. My structure is:


So far this is what I have… simplified:

class ClassOne : public ofxFadeScene {
    float theradius;

void setup(){}
void update(){}
void draw(){
ofSetColor(255, 55, 55);
ofCircle(ofGetWidth()/2, ofGetHeight()/2, theradius);


And setting it from ClassTwo with:

ClassOne *c1ptr;

void setup(){
	c1ptr = (ClassOne*)ofGetAppPtr();
void update{
	c1ptr->theradius = 400;

Are pointers even the best way to go at this? Any help appreciated.

as a general rule you don’t want to be directly accessing and changing variables of your classes anyways. You should make getter/setter functions like getRadius() and setRadius(float r) instead. Pointers are fine but creating a default constructor and avoiding having to deal with dynamic memory allocation can prevent issues during runtime.


I am no expert in C++ either so i may be wrong, but i would also go for getters / setters and pass variables by reference when dealing with large properties when needed.

I also sometimes use Listeners along with ofParameters.

When i need to modify variables with a gui i usually use ofParameterGroup

i sometimes use SINGLETON which is kind of a global variable