-1

I am new to SDL and I obviously face difficulties, but I was able to solve them after some research. But this is a different one that I can't solve myself. It may seem stupid, but I have really no idea what could be wrong.

I am trying to make a SDL_Rect struct for one of my images that I will hopefully render on the screen. I expected it to go flawless because I double checked it from a couple sites and I was pretty confident I knew how to do it. What you will see is only my header file, if it is not enough for the problem I will add additional info.

#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);
}; 

Then I received these errors for each of Steve's members respectively:

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 ';'

I got desperate and tried copy-pasting from tutorials and got the same result. I am working with Visual Studio 2019 and I have the red curly line (the one for errors) under every "steve" and the dot next to him except the first one(row 15). I haven't done nothing with Steve yet because I got scared from the errors and it was working perfectly without it so I expect the error to be between row 14 and 21.

Any help is well appreciated.

1 Answers1

1

Write a constructor for your class.

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;
    ...
};

This is basic C++. Perhaps you should spend some time learning C++ first, before you try SDL? Things will definitely go more smoothly that way. You can find book recommendations here.

john
  • 85,011
  • 4
  • 57
  • 81
  • 1
    I know, I know. I have worked with other languages and currently I might have over evaluated myself. Thanks for the advice. – Victor Ivanov Aug 20 '20 at 13:33