【问题标题】:error: `MEMBER` in `class CLASS` does not name a type; C++错误:“class CLASS”中的“MEMBER”没有命名类型; C++
【发布时间】:2015-02-11 21:03:05
【问题描述】:

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

错误:“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 编译器。 请帮帮我

【问题讨论】:

    标签: c++ gcc sfml


    【解决方案1】:

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

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

    【讨论】:

    • 就是这样,你是我的英雄 :)
    【解决方案2】:

    赋值时这些变量的类型信息丢失了。

    这应该可以解决它:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多