简体   繁体   中英

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:

Player *player = new Player;

Ideally, you should initialize player in the constructor of Map . That will allow you to avoid #include ing "Player.h" in "Map.h".

Also, you should add

#include <vector>
#include <string>

since you are using

std::vector <std::string> levelData;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM