我是 C++ 的新手,我正在尝试制作一款地牢爬虫小游戏。目前我在我的头文件中声明了多个 vector ,但它们似乎给出了多个错误。我曾尝试在 StackOverflow 上搜索此问题,但答案似乎并不奏效。
这是我的头文件之一:(Hero.h)
#pragma once
class Hero {
public:
Hero();
std::string name;
int experience;
int neededExperience;
int health;
int strength;
int level;
int speed;
std::vector<Item> items = std::vector<Item>();
void levelUp();
private:
};
这是我的.cpp 文件:(Hero.cpp)
#include "stdafx.h"
#include <vector>
#include "Hero.h"
#include "Item.h"
Hero::Hero() {
}
void Hero::levelUp()
{
};
就像我说的,我是 C++ 的新手,所以我的代码可能有比我知道的更多的错误。这只是一个测试。
以下是 Visual Studio 2015 错误列表中显示的错误:
Error C2039 'vector': is not a member of 'std' CPPAssessment hero.h 13
Error C2143 syntax error: missing ';' before '<' CPPAssessment hero.h 13
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int CPPAssessment hero.h 13
Error C2238 unexpected token(s) preceding ';' hero.h 13
最佳答案
包括<vector>
在您的 Hero.h header 中,并考虑将其从您的 Hero.cpp 文件中删除,如以下评论中所述。
关于c++ - 错误 C2039 : 'vector' : is not a member of 'std' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39765112/