beginning steps of...

hi guys

i was taking the beginning steps of making my own window through using SDL2. and just as i was expecting i stuck at some point by taking this error.

here is my codes:
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifdef __cplusplus
    #include <cstdlib>
#else
    #include <stdlib.h>
#endif

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <string>
#include "window.h"

int main ( int argc, char** argv )
{
    window mw;

    SDL_Window *sdlWindow;

    if(SDL_Init(SDL_INIT_EVERYTHING) != 0)  return 1;

    sdlWindow = mw.create_window("ff", 640, 480);

    SDL_Renderer* ren = SDL_CreateRenderer(sdlWindow, -1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC);
    if(ren == NULL)                         return 3;

    SDL_Delay(2000);

    SDL_DestroyRenderer(ren);
    SDL_DestroyWindow(sdlWindow);
    SDL_Quit();

    return 0;
}


window.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef WINDOW_H
#define WINDOW_H

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

class window
{
    public:
        window();
        SDL_Window create_window(std::string win_title, int win_width, int win_height);
    protected:
    private:
        SDL_Window              *win;
};

#endif // WINDOW_H 


window.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "window.h"

window::window()
{
    win = NULL;
}

SDL_Window window::create_window(std::string win_title, int win_width, int win_height)
{
    win = SDL_CreateWindow(win_title.c_str,
                           SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
                           win_width, win_height,
                           SDL_WINDOW_BORDERLESS|SDL_WINDOW_SHOWN|SDL_WINDOW_RESIZABLE);

    return win;
}


EDIT: opps sorry. i forgot to add given error

C:\Users\Ceset\Desktop\test\main.cpp||In function 'int SDL_main(int, char**)':|
C:\Users\Ceset\Desktop\test\main.cpp|21|error: invalid use of incomplete type 'SDL_Window {aka struct SDL_Window}'|
C:\SDL 2.0.0\include\SDL2\SDL_video.h|89|error: forward declaration of 'SDL_Window {aka struct SDL_Window}
Last edited on
For window::create_window, you accidentally forgot to add the asterisk * to indicate that it returns a pointer.
haha. thx

and also i found out that i forgot to add () to c_str() func
Out of curiosity. why did you create a seperate class file for window?

If you wanted just the functionality of the functions in it, you could put everything into the header file, drop the cpp file and the objects in the source.

That's what I would do at least. As long as it remains function/definition based, without referencing in external objects.
@roger911: aside from differing compilation times, it's just personal preference.
yes like @L B said it is preference. i m planning a complex and a big class(at least for me). so i like it this way
Topic archived. No new replies allowed.