2015-02-11 94 views
1

嘿,我已经构建了一个类来存储一些信息作为类的静态成员。 在编译时我得到了错误:config.h中错误:`class CLASS`中的'MEMBER`没有指定类型; C++

error: ‘cubeLength’ in ‘class Config’ does not name a type

error: ‘cellColor’ in ‘class Config’ does not name a type

内容

#ifndef CONFIG_H 
#define CONFIG_H 

#include <SFML/Graphics.hpp> 

class Config { 
public: 
    static float  cubeLength ; 
    static sf::Color cellColor; 
private: 
    Config(); 
    Config(const Config& orig); 
}; 

Config::cubeLength = 10.f; //error thrown here 
Config::cellColor = sf::Color::Magenta; //error thrown here 


#endif /* CONFIG_H */ 

我使用GNU编译器在Linux上。 请帮我出

回答

2

由于错误状态,您需要在减速时输入类型信息。您需要有:

float Config::cubeLength = 10.f; 
sf::Color Config::cellColor = sf::Color::Magenta; 
+0

就是这样,你是我心目中的英雄:) – 2015-02-11 21:10:32

1

当您进行分配时,缺少这些变量的类型信息。

这应该修复它:

static float Config::cubeLength = 10.f; 
static sf::Color Config::cellColor = sf::Color::Magenta;