我有这个代码:(BITMAPS
是一个免费的名字)
class BITMAPS{
public:
static ALLEGRO_BITMAP *cursor;
static void load_bitmaps();
static void unload_bitmaps();
};
我正在尝试像这样使用它:(有错误的行)
line 9: BITMAPS.load_bitmaps();
line 23: BITMAPS.unload_bitmaps();
line 36: BITMAPS.cursor;
但我收到这样的错误:(错误)
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
问题是什么?
编辑:
我已经将 . 更改为 :: 现在我得到了这个:
unresolved external symbol "public: static struct ALLEGRO_BITMAP * BITMAPS::cursor" (?cursor@BITMAPS@@2PAUALLEGRO_BITMAP@@A)
这是什么意思?
最佳答案
您需要使用 Scope Resolution::
运算符来引用它们,而不是您正在使用的语法。
BITMAPS::load_bitmaps();
BITMAPS::unload_bitmaps();
BITMAPS::cursor;
编辑:回答您更新后的问题
您刚刚声明静态成员cursor
,您还需要定义它,在您的源代码(cpp
) 文件。
喜欢:
ALLEGRO_BITMAP* BITMAPS::cursor = 0;
好读:
<强> what does it mean to have an undefined reference to a static-member?
建议:
你应该阅读 good C++ book.
关于C++ 静态类成员 - 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7840692/