- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这是我第一次在 stackoverflow 上发帖,所以希望这是遵守所有礼仪!
我正在尝试使用 SDL 1.x 扩展库在 C++ 中创建和实现按钮类,以便与使用有限状态机的个人项目一起使用。我有一个带有虚函数的基类“Button”,一个派生自 Button 的类“MenuButton”,以及一个尝试创建 MenuButton 的“Title”状态。
我使用的是 Microsoft Visual Studio 2012,Intellisense 说我的代码是正确的。然而,当我尝试编译时,我收到以下两个错误:
title.h(35): error C2143: syntax error : missing ';' before '*'
title.h(35): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
我花了几个小时试图自己解决问题。我在 google 上搜索过,也一直在搜索 stackoverflow,但是虽然我看到并阅读了许多其他有类似问题的帖子,但似乎没有一个与我有同样的问题。
基于其他人发布的其他类似问题以及他们接受的答案,我已经搜索过:#include 循环问题,确保类声明具有最终的 ;,并确保包含所有 #includes(我知道)。
下面是代码片段,如果有人能告诉我如何解决这个问题,我将不胜感激。
谢谢
Button.h(基类)
#ifndef BUTTON_H
#define BUTTON_H
#include "SDL.h"
#include "SDL_image.h"
#include "SDL_ttf.h"
#include "Functions.h"
#include "Globals.h"
#include "Constants.h"
#include <string>
using namespace std;
class Button
{
public:
virtual void handleEvents() = 0;
virtual void render() = 0;
//virtual ~Button(void){};
protected:
//Our enumerated type
const enum mouseStates {CLIP_MOUSEOUT, CLIP_MOUSEOVER, CLIP_MOUSEDOWN, CLIP_MOUSEUP};
//Our rect to hold the offsets and size of the button
SDL_Rect button;
//Array of rects to hold the dimensions of each clip from the sprit sheet
SDL_Rect clips[4];
//Holds the location and size of the clip to show from sprite sheet
SDL_Rect *clip;
//The sprite sheet surface from which we clip the button images
SDL_Surface *buttonSpriteSheet;
//The surface for our button text
SDL_Surface *buttonSurfaceText;
//The text for our button
string buttonText;
//The state the button will lead to when clicked
GameStates targetState;
//Whether we are moused over the button
bool mouseOver;
};
#endif
MenuButton.h(派生类)
#ifndef MENUBUTTON_H
#define MENUBUTTON_H
#include "button.h"
using namespace std;
class MenuButton :
public Button
{
public:
MenuButton(void);
MenuButton(int x, int y, int w, int h, string text, GameStates state);
void handleEvents();
void render();
~MenuButton(void);
};
#endif
Title.h(创建按钮并抛出错误的状态)
#ifndef TITLE_H
#define TITLE_H
#include "GameState.h"
#include "SDL.h"
#include "SDL_image.h"
//#include "SDL_Mixer.h"
#include "Functions.h"
#include "Globals.h"
#include "Constants.h"
#include "MenuButton.h"
#include <iostream>
#include <string>
using namespace std;
class Title :
public GameState
{
public:
Title(void);
//Handles intro events
void handleEvents();
//Handles intro logic
void logic();
//Handles intro rendering
void render();
~Title(void);
private:
SDL_Surface *background;
MenuButton *testButton; //NOTE: This is the line throwing the errors
//Mix_Music *music;
};
#endif
感谢您的协助!~<3
最佳答案
编译器似乎不知道MenuButton
是什么。出现这种情况的一个原因是 MENUBUTTON_H
也由另一个 header 定义。更有可能的是,类似 Globals.h
的内容也包含 "title.h"
,即您的系统中有一个依赖循环。如果你知道类是循环依赖的,你最好去掉循环。有很多方法可以做到这一点。即使您当前认为您需要循环依赖,它也不是很好而且可能不需要(John Lakos 的“Large Scale C++ Design”一书包含了很多关于如何打破依赖循环的信息)。
如果您不知道循环从何而来,我建议您在编译器中使用 -E
(或 /E
)标志:此选项通常会产生预处理后的翻译单元。它将包含以某种形式输入的文件的指示。预处理输出的外观取决于编译器,但您将能够看到编译器看到的内容,并且您可能可以找到未声明 MenuButton
的原因。
作为一种简单的方法,您还可以确保声明了 MenuButton
:要形成一个指针,您不需要它的定义。在实际访问指针时看到定义就足够了。声明看起来像这样:
class MenuButton;
.. 并且可以在每个翻译单元中重复使用 MenuButton
来声明 MenuButton
的指针或引用成员。您甚至可以仅通过声明声明按值返回或传递 MenuButton
的函数。当然,当你想实际使用该类型时,你需要查看它的定义。
关于c++ - 声明从具有虚函数的基类派生的对象时出现错误 c2143 和 c4430,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13906724/
这是代码片段。 请说出这种用小内存存储大数据的算法是什么。 public static void main(String[] args) { long longValue = 21474836
所以我使用 imap 从 gmail 和 outlook 接收电子邮件。 Gmail 像这样编码 =?UTF-8?B?UmU6IM69zq3OvyDOtc68zrHOuc67IG5ldyBlbWFpb
很久以前就学会了 C 代码;想用 Scheme 尝试一些新的和不同的东西。我正在尝试制作一个接受两个参数并返回两者中较大者的过程,例如 (define (larger x y) (if (> x
Azure 恢复服务保管库有两个备份配置选项 - LRS 与 GRS 这是一个有关 Azure 恢复服务保管库的问题。 当其驻留区域发生故障时,如何处理启用异地冗余的恢复服务保管库?如果未为恢复服务启
说,我有以下实体: @Entity public class A { @Id @GeneratedValue private Long id; @Embedded private
我有下一个问题。 我有下一个标准: criteria.add(Restrictions.in("entity.otherEntity", getOtherEntitiesList())); 如果我的
如果这是任何类型的重复,我会提前申请,但我找不到任何可以解决我的具体问题的内容。 这是我的程序: import java.util.Random; public class CarnivalGame{
我目前正在使用golang创建一个聚合管道,在其中使用“$ or”运算符查询文档。 结果是一堆需要分组的未分组文档,这样我就可以进入下一阶段,找到两个数据集之间的交集。 然后将其用于在单独的集合中进行
是否可以在正则表达式中创建 OR 条件。 我正在尝试查找包含此类模式的文件名列表的匹配项 第一个案例 xxxxx-hello.file 或者案例二 xxxx-hello-unasigned.file
该程序只是在用户输入行数时创建菱形的形状,因此它有 6 个 for 循环; 3 个循环创建第一个三角形,3 个循环创建另一个三角形,通过这 2 个三角形和 6 个循环,我们得到了一个菱形,这是整个程序
我有一个像这样的查询字符串 www.google.com?Department=Education & Finance&Department=Health 我有这些 li 标签,它们的查询字符串是这样
我有一个带有静态构造函数的类,我用它来读取 app.config 值。如何使用不同的配置值对类进行单元测试。我正在考虑在不同的应用程序域中运行每个测试,这样我就可以为每个测试执行静态构造函数 - 但我
我正在寻找一个可以容纳多个键的容器,如果我为其中一个键值输入保留值(例如 0),它会被视为“或”搜索。 map, int > myContainer; myContainer.insert(make_
我正在为 Web 应用程序创建数据库,并正在寻找一些建议来对可能具有多种类型的单个实体进行建模,每种类型具有不同的属性。 作为示例,假设我想为“数据源”对象创建一个关系模型。所有数据源都会有一些共享属
(1) =>CREATE TABLE T1(id BIGSERIAL PRIMARY KEY, name TEXT); CREATE TABLE (2) =>INSERT INTO T1 (name)
我不确定在使用别名时如何解决不明确的列引用。 假设有两个表,a 和 b,它们都有一个 name 列。如果我加入这两个表并为结果添加别名,我不知道如何为这两个表引用 name 列。我已经尝试了一些变体,
我的查询是: select * from table where id IN (1,5,4,3,2) 我想要的与这个顺序完全相同,不是从1...5,而是从1,5,4,3,2。我怎样才能做到这一点? 最
我正在使用 C# 代码执行动态生成的 MySQL 查询。抛出异常: CREATE TABLE dump ("@employee_OID" VARCHAR(50)); "{"You have an er
我有日期 2016-03-30T23:59:59.000000+0000。我可以知道它的格式是什么吗?因为如果我使用 yyyy-MM-dd'T'HH:mm:ss.SSS,它会抛出异常 最佳答案 Sim
我有一个示例模式,它的 SQL Fiddle 如下: http://sqlfiddle.com/#!2/6816b/2 这个 fiddle 只是根据 where 子句中的条件查询示例数据库,如下所示:
我是一名优秀的程序员,十分优秀!