Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 班级不被承认?_C++_Sfml - Fatal编程技术网

C++ 班级不被承认?

C++ 班级不被承认?,c++,sfml,C++,Sfml,类中有一个类有一个Text成员,但给了我以下错误: Error 1 error C2146: syntax error : missing ';' before identifier 'text' Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 它们都位于struct MenuItem中的行文本上 这是菜单。h:菜单项

类中有一个类有一个Text成员,但给了我以下错误:

Error   1   error C2146: syntax error : missing ';' before identifier 'text'    
Error   2   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   
它们都位于struct MenuItem中的行文本上

这是菜单。h:菜单项在这里

#pragma once

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <Source/Text/Text.h>
#include <list>

class Menu {

    public:
        static enum MenuResult { Exit, Options, Back, ChangeResolution, Play, Nothing };

        MenuResult showMMenu(sf::RenderWindow &window);
        MenuResult showOMenu(sf::RenderWindow &window);
        MenuResult highlightButton(MenuResult menuresult);

        struct MenuItem {
            public:
                Text text;
                sf::FloatRect buttonrect;
                static void highlightRectOutline(sf::RenderWindow &window, Text text, sf::Color color);
                MenuResult action;
        };

    private:
        MenuResult getMenuResponse(sf::RenderWindow &window);
        MenuResult handleClick(int x, int y);
        MenuResult handleButtonHover(sf::RenderWindow &window, int x, int y);
        std::list<MenuItem> menuItems;

};
#pragma一次
#包括
#包括
#包括
#包括
班级菜单{
公众:
静态枚举菜单结果{Exit,Options,Back,changesolution,Play,Nothing};
菜单结果显示菜单(sf::渲染窗口和窗口);
菜单结果显示菜单(sf::渲染窗口和窗口);
MenuResult高亮按钮(MenuResult MenuResult);
结构菜单项{
公众:
文本;
sf::FloatRect按钮rect;
静态void highlightRectOutline(sf::RenderWindow&window、文本、sf::Color);
MenuResult行动;
};
私人:
MenuResult getMenuResponse(sf::渲染窗口和窗口);
MenuResult handleClick(整数x,整数y);
菜单结果把手按钮悬停(sf::渲染窗口和窗口,int x,int y);
std::列表菜单项;
};
h:这是MenuItem获取文本的地方

#pragma once

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

enum style { bold, italic, underlined };

class Text {

    public: 
        void create(sf::RenderWindow &window,
                    char* string, 
                    char* fontpath, 
                    float positionx, 
                    float positiony,
                    unsigned int size,
                    style textstyle,
                    sf::Color color);

        sf::FloatRect getRect();
        static float getHeight();
        static float getWidth();

        bool operator==(Text t);
        bool operator!=(Text t);

        void setString(sf::RenderWindow &window, char* string);
        sf::String getString();

        void setFont(sf::RenderWindow &window, char* fontpath);
        sf::Font getFont();

        void setPosition(sf::RenderWindow &window, float x, float y);
        static sf::Vector2f getPosition();  

        void setScale(sf::RenderWindow &window, float x, float y);
        sf::Vector2f getScale();

        void setColor(sf::RenderWindow &window, int red, int green, int blue, int alpha);
        sf::Vector3i getColor();

    private:
        static sf::Text text;
        sf::Font font;
};
#pragma一次
#包括
#包括
枚举样式{粗体、斜体、下划线};
课文{
公众:
void创建(sf::RenderWindow和window,
字符*字符串,
char*fontpath,
浮动位置X,
浮动位置,
无符号整数大小,
风格文本风格,
sf::颜色;
sf::FloatRect getRect();
静态浮动高度();
静态浮点getWidth();
布尔运算符==(文本t);
布尔运算符!=(文本t);
void setString(sf::RenderWindow&window,char*string);
sf::String getString();
void setFont(sf::RenderWindow&window,char*fontpath);
sf::Font getFont();
无效设置位置(sf::渲染窗口和窗口、浮动x、浮动y);
静态sf::Vector2f getPosition();
无效设置比例(sf::渲染窗口和窗口、浮动x、浮动y);
sf::Vector2f getScale();
void setColor(sf::RenderWindow&window、int-red、int-green、int-blue、int-alpha);
sf::Vector3i getColor();
私人:
静态sf::文本;
sf::字体;
};

这一行,在
Text.h
中:

static sf::Text text;
Text
未在
sf
命名空间中声明,因此此名称不存在

应该是:

static Text text;

这是因为我需要为类使用sf::Text中的函数。这就是为什么它与sf::font一起分组。@tetracomputerture:据我所知,您也没有包含
sf::Text
的标题(除非它碰巧被其他SFML包含项拉入),只包含“Source/Text/Text.h”,我假设它是您自己的
Text
类。我是。图形包括文本。如果我没有,我会因此而出错。这是完整的代码吗?您是否有可能在标头之间建立循环依赖关系?