Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6927081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:00:07+00:00 2026-05-27T11:00:07+00:00

I am creating a class where I defined a Struct called Room which I

  • 0

I am creating a class where I defined a Struct called “Room” which I declare as private in the header file. I have several public functions that require a “Room” as an argument. When I compile (in g++) I get an error saying:

Graph.h:42:17: error: "Room" has not been declared

Yet here lies the declaration (whole header file now):

#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

Are you not allowed to use structs defined inside the header file as arguments? If so, what’s the workaround?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:00:08+00:00Added an answer on May 27, 2026 at 11:00 am

    It compiles fine without the private: header. Why do you have this? Is the struct declared inside of a class?

    EDIT

    You have used Room before you declare it:

    const Room * findRoom( int roomNumber );
    

    Also, you can’t return a Room object through the public method you have declared, since outside code won’t know anything about it.

    You need to predeclare it before using it:

    class Graph {
    
    public:
    
    struct Room;
    
    const Room * findRoom( int roomNumber );
    
    struct Room
    {
        bool visted;
        int myNumber;
    
        Graph::Room *North;
        Graph::Room *East;
        Graph::Room *South;
        Graph::Room *West;
    };
    
    Room room;
    };
    
    int main (){
    
      Graph x;
    
      return 0;
    }
    

    Or you could just move the second private up, above the public section.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user defined class, say import java.util.Calendar; public class Employee{ private String
Assuming I have a shared activity class defined in a Library project, which does
I have a class defined as below: ref class myClass { PictureBox^ pic2; public:
Right now, I have a class defined as such: public class Task { public
When creating a class that has internal private methods, usually to reduce code duplication,
I am creating a class that determines which of number of registered WCF client
I'm creating a class that derives from List... public class MyList : List<MyListItem> {}
I just found myself creating a class called InstructionBuilderFactoryMapFactory. That's 4 pattern suffixes on
I am creating class instances by running a text file and slicing the words
i am developing a project in which i have used many classes. for creating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.