我有一个神秘的问题。在尝试在tour类中定义变量时,我不断得到'vector'并没有命名类型错误。库似乎安装正确,因为我可以在main中定义向量。根据这里的很多帖子,我检查了正确的向量包含和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
#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_ */
tour.cpp
#include<vector>
#include "tour.h"
using namespace std;
tour::tour(int id){
teamID = id;
}
这里可能有什么问题?
答案 0 :(得分:2)
不要写using namespace std;
和vector<int> tourseq;
,而应考虑撰写std::vector<int> tourseq;
。
你可能不应该在你的代码中添加using namespace std;
。