Accessing variable from other cpp file?

So I’ve declared a public variable in ofApp.h
Its value is being constantly updated in update() in ofApp.cpp

Now I want to access this value from secondFile.cpp … how would I do that?

Just referencing it is obviously now enough …


You could do this multiple ways,

  1. in update() call secondFile.setParam(value)
  2. From secondFile call ((ofApp *)ofGetAppPtr())->param

That depends. If your variable is mostly modified/used by secondFile.cpp, it might be a good idea to create a class object in secondFile.cpp and use it in in ofApp.cpp. That way the computing of the variable you want will be done inside a class.

However, if your variable is mostly used in ofApp.cpp and just validated inside secondFile.cpp, it might be a good idea to declare this variable as extern.