[英]'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.