[英]Does not name a type error
這是我遇到的最愚蠢的小問題,我找不到原因。
我知道已經問過很多錯誤,但是我讀到的每個錯誤都是關於聲明的順序的,但是,我在函數中使用struct之前先聲明了我的struct,但仍然得到該錯誤。
這是頭文件:
#ifndef GRAPH_H
#define GRAPH_H
#include <iostream>
#include <string>
using namespace std;
class Graph {
public:
struct Room;
// 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 , string str );
//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.
Room * findRoom( int roomNumber );
struct Room
{
bool visited;
int myNumber;
Room *North;
Room *East;
Room *South;
Room *West;
};
private:
int numRooms;
int _index;
int _start;
Room ** easyDelete;
string * escapePath;
Room * theWALL;
Room * safety;
};
#endif
具體錯誤是:錯誤:“房間”沒有命名類型,它在談論我的
Room * findRoom( int roomNumber );
函數,應該返回指向“房間”的指針。 我嘗試將結構的實際定義放在“結構室”中。 是,無濟於事。
#include <iostream>
#include <string>
#include "Graph.h"
using namespace std;
...
Room * Graph::findRoom( int roomNumber )
{
...
}
您確定錯誤指向此.h文件嗎? 不應有此錯誤...
如果您這樣編寫實現(在.cpp中)
Room * Graph::findRoom( int roomNumber );
它應該抱怨,因為Room是Graph的一部分:
Graph::Room * Graph::findRoom( int roomNumber );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.