C++静态类成员 - 语法错误

Vla*_*adp 1 c++ static class syntax-error

我有这个代码:( BITMAPS是一个免费的名字)

class BITMAPS{
public:
    static ALLEGRO_BITMAP *cursor;

    static void load_bitmaps();
    static void unload_bitmaps();
};
Run Code Online (Sandbox Code Playgroud)

我试图像这样使用它:( 有错误的行)

line 9:   BITMAPS.load_bitmaps();
line 23:  BITMAPS.unload_bitmaps();
line 36:  BITMAPS.cursor;
Run Code Online (Sandbox Code Playgroud)

但我得到这样的错误 :( 错误)

line 9 and 23:    syntax error : missing ';' before '.'
line 36:          token '.' is illegal after UDT 'BITMAPS'
line 36:          'BITMAPS' : illegal use of this type as an expression
line 36:          left of '.cursor' must have class/struct/union
Run Code Online (Sandbox Code Playgroud)

问题是什么?

编辑:

我改变了.::现在我得到了这个:

unresolved external symbol "public: static struct ALLEGRO_BITMAP * BITMAPS::cursor" (?cursor@BITMAPS@@2PAUALLEGRO_BITMAP@@A)
Run Code Online (Sandbox Code Playgroud)

这是什么意思?

Alo*_*ave 11

您需要使用" 范围分辨率"::运算符来引用它们,而不是您正在使用的语法.

BITMAPS::load_bitmaps();
BITMAPS::unload_bitmaps();
BITMAPS::cursor;
Run Code Online (Sandbox Code Playgroud)

编辑:回答您更新的问题

您刚刚在source()文件中声明了静态成员cursor,还需要定义cpp.
喜欢:

ALLEGRO_BITMAP* BITMAPS::cursor = 0;
Run Code Online (Sandbox Code Playgroud)

好读:
对静态成员有一个未定义的引用是什么意思?

建议:
你应该阅读一本好的C++书.