c++ - 错误 : `MEMBER` in `class CLASS` does not name a type; C++

标签 c++ gcc sfml

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

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

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

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 编译器。 请帮帮我

最佳答案

如错误所述,您需要在减速中获得类型信息。您需要:

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

关于c++ - 错误 : `MEMBER` in `class CLASS` does not name a type; C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28464430/

相关文章:

c++ - friend 类声明和使用指令

c++ - 如何安装依赖libstdc++库的程序

c++ - GCC 编译器警告溢出

c++ - 如何调用在另一个文件中找到的函数?

c++ - while循环困惑

c++ - 我在 SFML sf::RenderWindow 中只有黑屏

c++ - 制作变量列表而不复制它们

C++11 修改 std::discrete_distribution 中的值

c++ - 模板类中的尾随返回类型(GNU 和 Microsoft 编译器之间的矛盾)

c++ - noexcept 运算符和 enable_if_t : do they work together?