我正在开发一个自组织地图程序。 对此,我正在尝试创建一种可以集中所有可以设置的用户/开发人员变量的方法。我一直在尝试使用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