繁体   English   中英

没有命名错误

[英]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 );

函数,应该返回指向“房间”的指针。 我尝试将结构的实际定义放在“结构室”中。 是,无济于事。

编辑:对不起,使用时它在我的.C文件中:

#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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM