添加成员时,我的SDL_Rect结构给我错误C3927,C3484,C3613,C3646,C2059和C2238

问题描述

我是SDL的新手,我显然面临困难,但是经过一些研究,我能够解决这些问题。但这是另一种我无法解决的问题。可能看起来很愚蠢,但我真的不知道怎么了。

我正在尝试为我希望在屏幕上呈现的图像之一创建SDL_Rect结构。我希望它会完美无瑕,因为我在几个站点上都对其进行了仔细检查,并且我非常确信自己知道该怎么做。您将看到的只是我的头文件,如果不足以解决问题,我将添加其他信息。

#include <SDL.h>
#include <string>

using namespace std;

class GeneralStuff
{
public:
    bool quit;
    SDL_Renderer* renderer = NULL;

    // steve is 445 x 741,with no good LCM,in case you forget future me

    SDL_Rect steve;

    steve.x = 300;
    steve.y = 150;
    steve.w = 445;
    steve.h = 741;

    void QuitCheck();
    void init();
    SDL_Texture* load_image(SDL_Texture* the_texture,string path);
}; 

然后我分别收到每个Steve成员的错误

1>C:\Users\SecretName\Downloads\CodingJeff\SDL_Test\SDL_Project\GeneralStuff.h(17,7): error C3484: Syntax error: expected '->' before the return type
1>C:\Users\SecretName\Downloads\CodingJeff\SDL_Test\SDL_Project\GeneralStuff.h(17,10): error C3613: missing return type after '->' ('int' assumed)
1>C:\Users\SecretName\Downloads\CodingJeff\SDL_Test\SDL_Project\GeneralStuff.h(17,10): error C3646: 'x': unkNown override specifier 
1>C:\Users\SecretName\Downloads\CodingJeff\SDL_Test\SDL_Project\GeneralStuff.h(17,10): error C2059: Syntax error: '='
1>C:\Users\SecretName\Downloads\CodingJeff\SDL_Test\SDL_Project\GeneralStuff.h(17,15): error C2238: unexpected token(s) preceding ';'

我拼命地尝试了教程中的复制粘贴操作,并得到了相同的结果。我正在使用Visual Studio 2019,并且在每个``史蒂夫''下都有红色的卷曲线(表示错误的线条)以及除第一个(第15行)之外他旁边的点。我还没有对Steve做任何事情,因为我被错误吓到了,如果没有它,它就可以正常工作,所以我希望错误发生在第14到21行之间。

我们非常感谢您的帮助。

解决方法

为您的课程写一个构造函数。

class GeneralStuff
{
public:
    GeneralStuff()
    {
        steve.x = 300;
        steve.y = 150;
        steve.w = 445;
        steve.h = 741;
    }
    bool quit;
    SDL_Renderer* renderer = NULL;

    // steve is 445 x 741,with no good LCM,in case you forget future me

    SDL_Rect steve;
    ...
};

这是基本的C ++。也许您应该在尝试SDL之前先花一些时间学习C ++?这样一来,事情肯定会更加顺利。您可以找到推荐书here