2015-02-11 93 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;