[英]Does not name a type error
This is the dumbest little problem I am having and I CANNOT find the reason. 这是我遇到的最愚蠢的小问题,我找不到原因。
I am aware that there are dozens and dozens of this error already asked, but every one I read was about the order of declaration, however, I declare my struct before I use it in a function, and still get the error. 我知道已经问过很多错误,但是我读到的每个错误都是关于声明的顺序的,但是,我在函数中使用struct之前先声明了我的struct,但仍然得到该错误。
Here is the header file: 这是头文件:
#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
The specific error is: error: "Room" does not name a type, and it is talking about my 具体错误是:错误:“房间”没有命名类型,它在谈论我的
Room * findRoom( int roomNumber );
function, which is supposed to return a pointer to a "Room." 函数,应该返回指向“房间”的指针。 I have tried putting the actual definition of the struct where the "struct Room;"
我尝试将结构的实际定义放在“结构室”中。 is, to no avail.
是,无济于事。
#include <iostream>
#include <string>
#include "Graph.h"
using namespace std;
...
Room * Graph::findRoom( int roomNumber )
{
...
}
are you sure the error is pointing to this .h file? 您确定错误指向此.h文件吗? there shouldn't be this error...
不应有此错误...
if you write the implementation (in .cpp) like this 如果您这样编写实现(在.cpp中)
Room * Graph::findRoom( int roomNumber );
it should complain, because Room is a part of Graph: 它应该抱怨,因为Room是Graph的一部分:
Graph::Room * Graph::findRoom( int roomNumber );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.