C++静态类成员 - 语法错误
我有这个代码:(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用范围解析
::
运算符来引用它们,而不是您正在使用的语法。编辑:要回答您更新的问题,
您刚刚声明静态成员
cursor
,您还需要定义它,在您的源代码(cpp
) 文件。喜欢:
好读:
它有什么作用意味着对静态成员有未定义的引用?
建议:
您应该阅读一本优秀的 C++ 书籍
You need to use the Scope Resolution
::
operator to refer to them, and not the syntax you are using.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:
Good Read:
what does it mean to have an undefined reference to a static-member?
Suggestion:
You should read a good C++ book.