类未被识别
Class not being recognized?
本文关键字:识别 更新时间:2023-10-16
类中有一个类具有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
它们都在结构MenuItem中的Text文本行上。
这是Menu.h:这是MenuItem所在的
#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;
};
这就是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;
};
此行,在Text.h
:中
static sf::Text text;
Text
未在sf
命名空间中声明,因此此名称不存在。
应该是:
static Text text;
相关文章:
- 提升 ASIO 无法识别计时器对象
- 从udp接收帧对于人脸识别来说太慢
- 模板类无法识别友元运算符
- std::visit无法识别类型
- 无法识别模板功能
- 我有两个类需要在同一 cpp 文件中相互引用,但第一个类无法识别第二个类类型的对象
- 如何在LLVM中dyn_cast以识别StoreInst?
- 从不同的附加依赖项中识别等同命名的函数
- C++出现控制台错误.我无法识别源代码的问题
- VSCode IntelliSense无法识别SDL框架的SDL_image扩展库
- Qt:"Q3DScatter"即使包含在内也无法识别
- 使用指针的类识别
- 如何静态识别动态堆分配?
- 为什么C++无法识别我的对象实例化?
- C++ 无法识别创建进程'telnet'
- 识别 2D 矢量C++中的位置
- 如何识别项目是 QT 中的文件还是文件夹
- ESP32 无法识别任何设备已连接到其接入点
- 无法识别 Mac c++ 文件系统库
- 识别数组中的重复元素?