Reputation: 4320
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.
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 )
{
...
}
Upvotes: 0
Views: 4054
Reputation: 1569
are you sure the error is pointing to this .h file? there shouldn't be this error...
if you write the implementation (in .cpp) like this
Room * Graph::findRoom( int roomNumber );
it should complain, because Room is a part of Graph:
Graph::Room * Graph::findRoom( int roomNumber );
Upvotes: 5