'vector'不命名类型
'vector' does not name a type
我对c++相当陌生,&我有一个问题,声明向量作为一个类变量。我使用类似的策略让它们在代码的其他地方工作,但它不喜欢我的头文件。
error: ‘vector’ does not name a type
error: ‘vector’ has not been declared
error: expected ‘,’ or ‘...’ before ‘<’ token
error: ‘vector’ does not name a type
我已经注释了GCC指出的问题行。
#ifndef HEADER_H
#define HEADER_H
#include <cstdlib>
#include <vector>
#include <string>
using std::string;
// Class declarations
class Node {
int id;
string type;
public:
Node(int, string);
int get_id();
string get_type();
string print();
};
class Event {
string name, date, time;
public:
Event(string, string, string);
string get_name();
string get_date();
string get_time();
string print();
};
class Course {
char id;
std::vector<Node*> nodes[40]; // This one
public:
Course(char, std::vector<Node*>); // This one
char get_id();
std::vector<Node*> get_nodes(); // & this one.
string print();
};
class Entrant {
int id;
Course* course;
string name;
public:
Entrant(int, char, string);
int get_id();
Course* get_course();
string get_name();
string print();
};
// Function declarations
void menu_main();
void nodes_load();
void event_create();
void entrant_create();
void course_create();
#endif /* HEADER_H */
下面是我的IDE错误的截图,如果这给了更多的线索。
从实际编译代码中我可以看到的唯一问题是,您在Entrant
类中使用Course
,但此时您没有Course
的定义。
如果在Entrant
之上转发声明Course
,如下所示:
class Course;
class Entrant { }; //class definition
然后你的代码编译,根据这个活的例子
你在作弊;-)。你给我们的代码有std::vector
,可以工作,而你的截图中的代码有vector
,不能工作(编译器不知道从哪里得到它)。
解决方案:将代码更改为使用std::vector
安装了吗?也许这对你有帮助http://ubuntuforums.org/showthread.php?t=1261897
相关文章:
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- ";结果类型必须是可从输入范围的值类型""构造的;创建std::vector时
- 推导 std::vector::back() 的返回类型
- 将用户定义的类型与 std::vector 和 std::sort 一起使用
- 在自定义 std::vector-like 容器中处理指针和非指针模板类型的最佳方法是什么?
- C++如何在类Vector中显示不同类型的参数
- 将 std::vector::d ata 传递给函数期望类型**(双指针)
- 如何将 n 个连续元素插入到元素类型不可复制的 std::vector 中?
- 在设计方面:重载vector类型的类成员的插入运算符
- 在从仅移动类型派生的类中定义析构函数在使用 std::vector emplace_back或push_back创建时会
- 如何在OpenCV中存储部分轮廓点喜欢新矢量中的左侧,该类型为<vector<vector<Point>>
- 如何将 Python 对象转换为 Cython 扩展类型的 std::vector 并返回?
- 如何为数据类型 vector<glm::vec3> (opengl 数据类型) 编写 std::minmax 函数的自定义比较器
- 在函数调用中使用类型vector<pair<int,int>>::iterator&in
- 代码不适用于 C++ 中的泛型类型 Vector。<T>
- 错误:无法使用初始值设定项列表初始化非聚合类型 'vector<string>'
- 对于类型"vector<bitset<8>>"c++ 没有可行的重载运算符[]
- 返回类型Vector
- 对持有unique_ptr类型vector的对象列表进行排序
- 错误:无法使用初始值设定项列表初始化非聚合类型 'vector<int>'