我正在創建一個類,我定義了一個名爲「Room」的結構,我在頭文件中聲明爲private。我有幾個需要「房間」作爲參數的公共職能。當我編譯(以g ++)我得到一個錯誤說:使用結構作爲參數:錯誤:未定義的結構
Graph.h:42:17: error: "Room" has not been declared
然而,這裏存在申報(整個頭文件現在):
#ifndef GRAPH_H
#define GRAPH_H
#include <iostream>
#include <string>
using namespace std;
class Graph {
public:
// destructor
~Graph();
// copy constructor
Graph(const Graph &v);
// assignment operator
Graph & operator = (const Graph &v);
//Create an empty graph with a potential
//size of num rooms.
Graph(int num);
//Input the form:
//int -- numRooms times
//(myNumber north east south west) -- numRooms times.
void input(istream & s);
//outputs the graph as a visual layout
void output(ostream & s) const;
//Recursively searches for an exit path.
void findPath(Room start);
//Moves room N E S or W
void move(Room &*room , String direction);
//inputs the starting location.
void inputStart(int start);
//Searches the easyDelete array for the room with the
//number "roomNumber" and returns a pointer to it.
const Room * findRoom(int roomNumber);
private:
struct Room
{
bool visted;
int myNumber;
Room *North;
Room *East;
Room *South;
Room *West;
};
int numRooms;
int _index;
int _start;
Room ** easyDelete;
string * escapePath;
Room * theWALL;
Room * safety;
};
#endif
你是不是允許使用標頭中定義結構文件作爲參數?如果是這樣,解決方法是什麼?
謝謝。
什麼是'私人:'爲什麼? –
我認爲這是一個嵌套結構 – ThomasMcLeod
這不是完整的代碼,只是一個片段。如果您願意,我可以發佈整件事情。雖然這不算小。 – Joshua