我正在開發一個自組織地圖程序。 對此,我正在嘗試創建一種可以集中所有可以設置的用戶/開發人員變量的方法。我一直在嘗試使用Config.h/.cpp文件,但我不確定這是否是正確/最好的方法。創建集中式變量文件
看來,如果我不以正確的方式把它放在編譯錯誤。
問題是集中化必須在編譯和運行之間更改的變量的最佳/正確方法?
的config.h
#ifndef CONFIG_H_
#define CONFIG_H_
class Config{
public:
static const std::string outputFileLocation;//
static const std::string inputFilename;//
static const std::string outputFileExt;//
unsigned int vectorLength = 3;//RGB
//VARIBLE USED IN SOM CLASS
static const int NODE_GRID_HEIGHT = 100;
static const int NODE_GRID_WIDTH = 100;
};
#endif /* CONFIG_H_ */
Config.cpp
#include "Config.h"
//location to store output soms at it is iterated through
std::string Config::outputFileLocation = "/home/projectFiles/testMedia/results/mySom_";
//extension to put on output soms.
std::string Config::outputFileExt = ".jpeg";
////starting rgb image file to proccess
std::string Config::inputFilename = "/home/projectFiles/testMedia/yellowColor3.jpg";
////Length of muliti-dimensional data point. ie. a pixel.
unsigned int Config::vectorLength = 3;
在C++中,我非常肯定你必須在聲明它們時立即定義'const'變量;你可能想放棄'.cpp'文件,只使用一個頭文件。你能提供關於你得到的編譯器錯誤的更多細節嗎? – 2014-08-29 19:16:34
你的問題是什麼? – 2014-08-29 19:16:58
問題是集中化必須在編譯和運行之間更改的變量的最佳/正確方法? – 2014-08-29 19:21:20