Note that there are some explanatory texts on larger screens.

plurals
  1. POError: invalid use of member in static member function
    primarykey
    data
    text
    <p>I have two classes, and this is the header of one of them:</p> <pre><code>#ifndef WRAPPER_HPP #define WRAPPER_HPP #include &lt;SDL/SDL.h&gt; using namespace std; class Wrapper { private: //SDL_Surface *screen; public: static SDL_Surface *screen; static void set_screen(SDL_Surface *_screen); static void set_pixel(int x, int y, Uint8 color); static void clear_screen(int r, int g, int b); static SDL_Surface* load_image(char path[500]); static void draw_image(SDL_Surface *img, int x, int y, int width, int height); static void draw_line(int x1, int y1, int x2, int y2, Uint8 color); }; #endif </code></pre> <p>I am calling Wrapper::set_screen(screen) from another file and I get this error:</p> <pre><code>In file included from /home/david/src/aships/src/Wrapper.cpp:6:0: /home/david/src/aships/src/Wrapper.hpp: In static member function ‘static void Wrapper::set_screen(SDL_Surface*)’: /home/david/src/aships/src/Wrapper.hpp:11:18: error: invalid use of member ‘Wrapper::screen’ in static member function /home/david/src/aships/src/Wrapper.cpp:10:3: error: from this location </code></pre> <p>I also get a similar error for the definition of every single function on Wrapper.cpp, for example:</p> <pre><code>void Wrapper::set_pixel(int x, int y, Uint8 color) { /* Draws a pixel on the screen at (x, y) with color 'color' */ Uint8 *p; p = (Uint8 *) screen-&gt;pixels + y * screen-&gt;pitch + x * screen-&gt;format-&gt;BytesPerPixel; *p = color; } </code></pre> <p>On compile:</p> <pre><code>/home/david/src/aships/src/Wrapper.hpp: In static member function ‘static void Wrapper::set_pixel(int, int, Uint8)’: /home/david/src/aships/src/Wrapper.hpp:11:18: error: invalid use of member ‘Wrapper::screen’ in static member function /home/david/src/aships/src/Wrapper.cpp:17:17: error: from this location </code></pre> <p>I know it's related to the class being static and thus the variable Wrapper.screen is not accessible or something, but I'm not sure of how to fix it. Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload