我是 C++ 新手,我正在尝试制作一个小地牢爬行游戏。目前我在我的头文件中声明了多个向量,但它们似乎给出了多个错误。我曾尝试在 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
原文由 Jelmer 发布,翻译遵循 CC BY-SA 4.0 许可协议
在您的 Hero.h 标头中包含
<vector>
并考虑将其从您的 Hero.cpp 文件中删除,如下面的评论中所述。