在 C++ 头文件中声明向量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4230345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:53:35  来源:igfitidea点击:

Declaring vectors in a C++ header file

c++vector

提问by James W.

I am having some trouble with vector declarations in the header file of a C++ class I am making. My entire header file looks like this:

我在创建的 C++ 类的头文件中的向量声明有一些问题。我的整个头文件如下所示:

#ifndef PERSON_H
#define PERSON_H

#include "Message.h"
#include <string>
#include <vector>


class Person {

public:

 Person() {};
 Person(std::string emailAddress);

private:

 vector<Message> inbox;
 vector<std::string> contacts;
 std::string emailAddress;

};

#endif PERSON_H

My error occurs on the lines following the "private" declaration (where I declare my vectors). The error I am getting is C4430 - missing type specifier and and C2238 - unexpected tokens preceding ';'

我的错误发生在“私有”声明(我声明我的向量)之后的行上。我得到的错误是 C4430 - 缺少类型说明符和 C2238 - ';' 之前的意外标记

Thank you for any help.

感谢您的任何帮助。

回答by Moo-Juice

You're missing the namespace:

您缺少命名空间:

std::vector

回答by Edward Strange

You need to put 'std::' before 'vector' just like you did with string.

您需要像处理字符串一样将 'std::' 放在 'vector' 之前。

回答by drinu276

In my case, adding the namespace did not work, however, I was missing the

就我而言,添加命名空间不起作用,但是,我错过了

#include <vector>;