I went from this implementation of my ofApp.cpp (aka testApp.cpp):
#include "ofApp.h"
const ofColor bgColor(33, 33, 33);
void ofApp::setup() {
ofBackground(bgColor);
}
To this, in ofApp.h (aka testApp.h):
#pragma once
#include "ofMain.h"
class ofApp : public ofBaseApp {
public:
ofApp() : bgColor(ofColor(33, 33, 33)) {};
void setup();
// ...
void gotMessage(ofMessage msg);
private:
const ofColor bgColor;
};
I simply moved the global declaration of bgColor out of ofApp.cpp and into ofApp.h and added a constructor with an initialization list to initialize bgColor.
Is the latter the “right way” to do such a thing? (I’m having a hard time drawing the line between C++ practices and what is acceptable with the “OF style” of declaring globals at the top of ofApp.cpp.
Is it “better” to have declared members in ofApp.h and use an initialization list, rather than declare globals at the top of testApp.cpp ?
In a nutshell, the latter is the “right way.” A discussion on the OF forum is here.