[英]c++: Error: this declaration has no storage class or type specifier
Hello I'm pretty new to coding and have started with my first bigger project just to learn faster.您好,我对编码很陌生,并且已经开始了我的第一个更大的项目,只是为了更快地学习。
When I trying too allocate memory the error "this declaration has no storage class or type specifier" in the tool tip and then it wont compile.当我也尝试分配内存时,工具提示中出现错误“此声明没有存储类或类型说明符”,然后它将无法编译。
#ifndef MAP_H
#define MAP_H
#include "Headers.h"
#include "Player.h"
class Player;
class Map
{
public:
Map();
Player *player;
player = new Player;
std::vector <std::string> levelData;
void Draw();
void Create();
void Open();
void Save();
};
#endif
Player *player;
player = new Player;
is not right.是不正确的。 You cannot have a statement like the second line above in the middle of a class definition.在类定义的中间不能有像上面第二行这样的语句。
If you have a C++11 compliant compiler, you can use:如果你有一个 C++11 兼容的编译器,你可以使用:
Player *player = new Player;
Ideally, you should initialize player
in the constructor of Map
.理想情况下,您应该在Map
的构造函数中初始化player
。 That will allow you to avoid #include
ing "Player.h" in "Map.h".这将允许您避免在“Map.h”中使用#include
ing“Player.h”。
Also, you should add另外,你应该添加
#include <vector>
#include <string>
since you are using因为你正在使用
std::vector <std::string> levelData;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.