c++ - 错误 C2039 : 'vector' : is not a member of 'std'

标签 c++ visual-studio c++11 stdvector

我是 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/

相关文章:

c++ - 构造函数未调用预期次数

c++ - typename 语句中的 class 后跟 _t(下划线-t)代表什么?

c++ - 二叉搜索树崩溃

visual-studio - 如何更改 Visual Studio IDE 配置文件?

c++ - 为什么 pthread_key_create 析构函数被调用了几次?

c++ - ESP 的值没有正确保存

javascript - 为什么 Visual Studio 2005 不调试我的 JavaScript 代码?

visual-studio - 我可能会缺少Visual Studio 2008的哪些功能和快捷方式,如何找到?

C++ - 不明确的重载模板解析/推导

c++ - 使用 clang 优化进行编译时出现意外结果