C++ OpenFrameworks testApp拥有ofColor成员的“正确方法”?
我从我的ofApp.cpp(又称testApp.cpp)的这个实现开始:C++ OpenFrameworks testApp拥有ofColor成员的“正确方法”?,c++,openframeworks,C++,Openframeworks,我从我的ofApp.cpp(又称testApp.cpp)的这个实现开始: #include "ofApp.h" const ofColor bgColor(33, 33, 33); void ofApp::setup() { ofBackground(bgColor); } 对此,在ofApp.h(也称为testApp.h)中: #pragma once #include "ofMain.h" class ofApp : public ofBaseApp { public:
#include "ofApp.h"
const ofColor bgColor(33, 33, 33);
void ofApp::setup() {
ofBackground(bgColor);
}
对此,在ofApp.h(也称为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;
};
我只是将bgColor的全局声明从ofApp.cpp移到ofApp.h中,并添加了一个带有初始化列表的构造函数来初始化bgColor
后者是这样做的正确方式吗?我很难在C++实践中划出界限,在OpApp.CPP.</P>的顶部声明全局样式的方式是可以接受的。
在ofApp.h中声明成员并使用初始化列表是否比在testApp.cpp顶部声明全局成员更好?简而言之,后者是正确的方法。关于论坛的讨论