what your teacher said is true, but remember that there's a difference between declaring a varible and assigning a value to it. Everything in C++ has a scope When you do
void ofApp::setup() {
int x;
}
the variable X is destroyed as soon as the function call is over. However, if you declare a variable in the class body, that variable belongs to the class as a hole, and will have the same life span as the variable itself.
class ofApp : public ofBaseApp {
(...)
int x;
}
In this code, the variable X can be altered and seen by all the functions that belong to the class ofApp. That way you can later assign a value to it whenever you want
void ofApp::setup(){
x = 0;
}
void ofApp::update(){
x++;
}
the class ofApp is created in main.cpp in the line
ofRunApp(new ofApp());
and is only destroyed when the app window is closed.
In general, when working with the basics of openFrameworks, your whole program will be contained in the ofApp class. So, if you want a variable to be "global" you only need it to exist in the scope of the class ofApp. In other words, you need to declare it in the ofApp.h file, inside
class of App: public ofBaseApp{
}
To better understand scopes and duration of variables, take a look at this article.
This site helped me a lot when I was begining, hope it helps you too!