在 C++ 类定义中使用向量
using vector in c++ class definition
我有一个神秘的问题。在尝试在旅游类中定义变量时,我一直得到一个"vector"没有命名类型错误。该库似乎安装正确,因为我可以在 main 中定义向量。根据这里的许多帖子,我已经检查了正确的向量包含和 std 命名空间。我仍然收到错误。
主.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;
}
图尔·
#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_ */
旅游.cpp
#include<vector>
#include "tour.h"
using namespace std;
tour::tour(int id){
teamID = id;
}
这里可能出了什么问题?
与其写using namespace std;
,vector<int> tourseq;
不如考虑写std::vector<int> tourseq;
。
无论如何,您可能不应该在代码中放入using namespace std;
。
相关文章:
- 从具有自定义排序的向量创建集合
- 如何在 c++ 中定义接受不同参数类型的函数向量?
- C++ 向量与用户定义的类比较?(==, <, >)
- 从自定义类获取对象向量中的 max 元素
- 是否可以定义一个以向量<T>作为值的unordered_map?
- 自己的自定义向量类. 内存重新分配
- 当我尝试定义这个向量时<pair<int , pair<int, int> > > vp(n)
- 初始化用户定义类的指针向量
- C++类中的类作为自定义向量(如何初始化?
- 从自定义数据类型向量中删除重复元素
- C++:自定义数据类型向量错误的队列
- 如何避免自定义 STL 向量类的智能指针 delete[] 异常?
- C++向量类定义
- 在C++中使用带有自定义向量的迭代器
- 结构 (C++) 中的向量定义
- C ++ 11,为什么为向量定义unordered_map这个不起作用<int>?
- 返回的向量定义为 "std::vector<<error-type>, std::allocator<<error-type>>>
- 这些向量定义"constant initialization"吗?
- 为什么shared_ptr的这个向量定义可以通过编译器检查
- 程序卡在类的向量定义上