[英]'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
没有任何定义。
如果向前声明Course
略高于Entrant
就像这样:
class Course;
class Entrant { }; //class definition
然后,根据此实时示例编译您的代码
你在欺骗 ;-) 。 您提供给我们的代码具有std::vector
,它可以工作,而屏幕截图中的代码中的vector
不起作用(编译器不知道从何处获取)。
解决方案:更改您的代码以使用std::vector
。
您安装了Stl吗? 也许这会帮助您http://ubuntuforums.org/showthread.php?t=1261897
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.