Error: invalid use of member in static member function

后端 未结 3 1042
野性不改
野性不改 2021-01-05 03:01

I have two classes, and this is the header of one of them:

#ifndef WRAPPER_HPP
#define WRAPPER_HPP

#include 

using namespace std;

class W         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-05 03:16

    You are using a static variable

    static SDL_Surface *screen;
    

    in your code.

    In C++ when you declare a static variable in the .h (or .hpp) you are creating a variable that is general (static) to the class. Thus, to use it in another file you have to redeclare it (which I'm guessing you didn't) to create a variable in that file referencing the static one. In your case put this:

    SDL_Surface* Wrapper::screen;
    

    in the .cpp file.

    I'm not sure the theory is well explained, but it works like that.

提交回复
热议问题