与使用类有关的两个错误
Two errors to do with using a class
我收到以下两个错误:
sdlsetup.h(15): error C2143: syntax error : missing ';' before '*'
sdlsetup.h(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
这是第 15 行sdlsetup.h
:
CText* ctext;
该类绝对设置正确并包含在sdlsetup.h
这是为什么呢?
编辑:这是sdlsetup.h
#pragma once
#include "stdafx.h"
class SDLsetup
{
public:
SDLsetup();
~SDLsetup();
void Begin();
void End();
SDL_Renderer* GetRenderer();
void EnterGameLoop();
CText* ctext;
private:
SDL_Window* window;
SDL_Renderer* renderer;
SDL_Event* mainEvent;
int screenWidth;
int screenHeight;
};
这是Text.h
#pragma once
#include "stdafx.h"
class CText
{
public:
CText();
~CText();
void draw(SDL_Renderer* renderer, std::string str);
SDL_Texture* aGetMessage();
SDL_Rect* aGetMessageRect();
private:
TTF_Font* Sans;
SDL_Color White;
SDL_Surface* surfaceMessage;
SDL_Texture* Message;
SDL_Rect Message_rect;
};
这里的问题是编译器发出的奇怪错误消息,因为它不知道CText
是什么。
您需要在使用之前声明CText
:
#pragma once
// Declare the CText class, so the compiler knows it exists
class CText;
class SDLsetup
{
public:
...
CText* ctext;
...
};
您需要在 sdlsetup.h 中为 Text.h 添加包含,并在两个文件中为相关的 SDL 标头添加包含。
Text.h 需要包含 SDL.h
和 SDL_ttf.h
,sdlsetup.h 需要包含 SDL.h
和Text.h
相关文章:
- 如何确保在使用基于布尔值的两个方法之一调用方法时避免分支预测错误
- 两个线程一个使用流 Api,另一个线程创建文件失败并出现错误ERROR_SHARING_VIOLATION
- C++哈希表中,两个相同的实现,但一个给出错误
- 使用 SET(C++) 检查两个给定字符串是否是字谜时出现运行时错误
- C++ 分段错误:11 错误,同时编码将两个数字相加的链接列表
- 在 C++ 中创建两个不同的二叉树时出现分段错误
- 交换两个字符串时访问正确的内存时,我遇到了分段错误
- 试图添加两个矢量,但添加顺序错误
- pair的两个构造函数几乎相同,为什么不生成构建错误?
- 纠正C++学校图书馆管理程序中的两个错误
- C 编译时两个错误
- 在主函数c++中使用类时出现两个错误
- 评分程序中的两个错误
- 使用类和标头的两个错误
- 在编译程序之前,我不确定如何修复我的两个错误
- 我正在做一个学校项目,我遇到了两个错误,我不知道如何纠正它们,任何想法
- 我得到两个错误,但我不能识别它们
- 运算符重载 - 知道为什么我在 c++ 程序中遇到这两个错误吗?
- 与使用类有关的两个错误
- 需要一些帮助的两个错误(c++)