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

标签 c++ class static syntax-error

我有这个代码:(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/

相关文章:

c - 将函数中的静态变量初始化为非常量值

c++ - 如何在不使用赋值运算符的情况下为动态变量分配初始值?

c++ - 无法理解此语句 - 运算符后的返回类型

c++ - 通常对函数名的非限定查找与对变量名的查找不同吗?

class - 在 UML 类图中何时使用 memberEnd 以及 navigableOwnedEnd?

c# - 使类在程序集之外不可见

c++ - C++ 的自动代码风格指南测试

jquery - 如何获取最顶层的div父类

Java静态主要也codingBat

c++ - 静态模板函数的这种实现有什么问题?