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

发布于 2024-12-11 05:33:23 字数 940 浏览 0 评论 0原文

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

这是什么意思?

I have this code:(BITMAPS is a free name)

class BITMAPS{
public:
    static ALLEGRO_BITMAP *cursor;

    static void load_bitmaps();
    static void unload_bitmaps();
};

and I'm trying to use it like this:(the lines with the errors)

line 9:   BITMAPS.load_bitmaps();
line 23:  BITMAPS.unload_bitmaps();
line 36:  BITMAPS.cursor;

but I'm getting errors like this:(the errors)

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

what is the problem?

EDIT:

I've changed . to :: and now I'm getting this:

unresolved external symbol "public: static struct ALLEGRO_BITMAP * BITMAPS::cursor" (?cursor@BITMAPS@@2PAUALLEGRO_BITMAP@@A)

what is this mean?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪淡了忧伤 2024-12-18 05:33:23

您需要使用范围解析:: 运算符来引用它们,而不是您正在使用的语法。

BITMAPS::load_bitmaps();
BITMAPS::unload_bitmaps();
BITMAPS::cursor;

编辑:要回答您更新的问题,

您刚刚声明静态成员cursor,您还需要定义它,在您的源代码(cpp) 文件。
喜欢:

ALLEGRO_BITMAP* BITMAPS::cursor = 0;

好读:
它有什么作用意味着对静态成员有未定义的引用?

建议:
您应该阅读一本优秀的 C++ 书籍

You need to use the Scope Resolution:: operator to refer to them, and not the syntax you are using.

BITMAPS::load_bitmaps();
BITMAPS::unload_bitmaps();
BITMAPS::cursor;

EDIT: To answer your updated Q

You just declared the static member cursor, You also need to define it,in your source(cpp) file.
like:

ALLEGRO_BITMAP* BITMAPS::cursor = 0;

Good Read:
what does it mean to have an undefined reference to a static-member?

Suggestion:
You should read a good C++ book.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文