错误:`class CLASS`中的`MEMBER`没有命名类型; C ++

时间:2015-02-11 21:03:06

标签: c++ gcc sfml

嘿,我已经构建了一个类来存储一些信息作为类的静态成员。 在编译时我得到了错误:

  

错误:'class Config'中的'cubeLength'没有命名类型

     

错误:'class Config'中的'cellColor'没有命名类型

Config.h的内容

#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 */

我在Linux上使用GNU Compiler。 请帮帮我

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:1)

执行作业时,缺少这些变量的类型信息。

这应该解决它:

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