简体   繁体   中英

error: `MEMBER` in `class CLASS` does not name a type; C++

Hey there i have constructed a class to store some Information as static Members of the class. At Compile-time i got the error:

error: 'cubeLength' in 'class Config' does not name a type

error: 'cellColor' in 'class Config' does not name a type

Content of 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 */

I am using GNU Compiler on Linux. Please help me Out

As the error states you need to have the type information in the deceleration. You need to have:

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

The type information of those variables is missing when you do the assignment.

This should fix it:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM