C++ 在c++;类定义

C++ 在c++;类定义,c++,vector,C++,Vector,我有一个神秘的问题。在tour类中定义变量时,我一直得到一个“vector”并没有命名类型错误。该库似乎安装正确,因为我可以在main中定义向量。根据这里的许多帖子,我已经检查了正确的向量includes和std名称空间。但我还是得到了错误 main.cpp #include <vector> #include <iostream> #include <cstring> #include <stdio.h> #include <time.h&

我有一个神秘的问题。在tour类中定义变量时,我一直得到一个“vector”并没有命名类型错误。该库似乎安装正确,因为我可以在main中定义向量。根据这里的许多帖子,我已经检查了正确的向量includes和std名称空间。但我还是得到了错误

main.cpp

#include <vector>
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <cmath>
#include <cstdlib>
#include "tour.h"
using namespace std;

int main () {

        //vector declaration works here
return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括“tour.h”
使用名称空间std;
int main(){
//向量声明在这里起作用
返回0;
}
旅游

#ifndef TOUR_H_
#define TOUR_H_

#include<vector>
using namespace std;

class tour
{
    public:
      //variables
      int teamID;
      vector<int> tourseq; //this is where the error occurs

      //functions
      tour(int);

};

#endif /* TOUR_H_ */
\ifndef TOUR\H_
#定义巡更_
#包括
使用名称空间std;
集体游
{
公众:
//变数
int团队ID;
vector tourseq;//这是发生错误的地方
//功能
旅游(国际);
};
#endif/*巡回演出*/
tour.cpp

#include<vector>
#include "tour.h"
using namespace std;

tour::tour(int id){
teamID = id;
}
#包括
#包括“tour.h”
使用名称空间std;
tour::tour(int-id){
teamID=id;
}

这里可能有什么问题?

而不是使用名称空间std编写
向量tourseq考虑编写<代码> STD::向量ToeSeq;<代码>


您可能不应该使用名称空间std放置
在您的代码中。

看起来不像真正的代码。不过有一个提示:停止使用
名称空间
。只要说不。我打赌你的问题会在这个过程中消失。使用构造函数初始值设定项列表。你说没有真正的代码是什么意思,我把它剥离到最低相关部分,因为我认为这是这个网站上的最佳实践?无论如何,起初我并没有使用名称空间std,而是根据我看到的一篇帖子添加了它。删除它并不能解决问题。@dorien:您确定这段代码会产生错误吗?对我来说不是:@dorien这不是真正的代码()。这是“真实”代码,好吧。对不起,这是一个很好的建议,但是对于这个问题,它作为一个答案是没有意义的。我会完全删除“可能”这个词,以得到更好的建议。是的,我尝试了所有的方法。我一开始没有名称空间,但之所以这样做是因为我在某个地方读到了它。删除它无效。谢谢。我说“可能”是因为我认为可能有一些情况是有意义的(尽管除了肮脏的原型代码之外,我想不出任何其他情况——即使这样,我也不会使用它)@dorien,你能预处理编译单元吗?你在用什么编译器?