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

  • SEARCH
  • Home
  • 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 6066257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:28:53+00:00 2026-05-23T09:28:53+00:00

So, I sort of expect this to end up being a simple answer, but

  • 0

So, I sort of expect this to end up being a simple answer, but I’ve been hacking at it for a while now, and can’t seem to fix this issue. So I have a particular class, Intersection, that when included in any other header gives me:

error C2061: syntax error : identifier 'Intersection'

This is my Intersection header:

#ifndef INTERSECTION_H
#define INTERSECTION_H

#include "Coord.h"
#include "Road.h"
#include "TrafficLight.h"

class Intersection {
private:
    int id;
    Coord * midPoint;
    Road * northRoad;
    Road * eastRoad;
    Road * westRoad;
    Road * southRoad;
    TrafficLight * trafficLight;
public:
    Intersection(int, Coord *, Road *, Road *, Road *, Road *);
    ~Intersection();
    void transitionTrafficLight();
    int getId();
    Road * getNorthRoad();
    Road * getEastRoad();
    Road * getWestRoad();
    Road * getSouthRoad();
    TrafficLight * getTrafficLight();
};

#endif

Now, if I attempt to use this class elsewhere, I get the error. For example:

#ifndef ROAD_H
#define ROAD_H

#include "Coord.h"
#include "Intersection.h"
#include <string>

class Road {

public:
    enum LaneCount { TWO_LANE = 2, FOUR_LANE = 4 };
    Road(std::string, Coord *, Coord *, LaneCount, Intersection *, Intersection *, int);
//shortened

Particularly at the Road constructor (and any other classes which reference Intersection). I don’t think it’s a syntax problem, as Coord is another class, defined in the same manner, and the compiler (VS 2008) doesn’t complain about it. It’s just Intersection in particular that’s giving me this trouble. :/

I’m tagging it homework — it’s what it’s for, even though this is just an error I can’t get rid of rather than part of the problem.

Thoughts?

  • 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-23T09:28:53+00:00Added an answer on May 23, 2026 at 9:28 am

    It looks like the error is that you have two header files that are circularly including one another – intersection.h and road.h. Doing this tends to lead to weird surprises in C++ because of how include guards work. For example, suppose that I have two header files that look like this:

    // File: A.h
    #ifndef A_Included
    #define A_Included
    
    #include "B.h"
    
    class A {};
    
    void MyFunction(B argument);
    #endif
    

    and

    // File: B.h
    #ifndef B_Included
    #define B_Included
    
    #include "A.h"
    
    class B {};
    
    void MyOtherFunction(A argument);
    #endif
    

    Now, if I try to #include "A.h", then it expands out to

    // File: A.h
    #ifndef A_Included
    #define A_Included
    
    #include "B.h"
    
    class A {};
    
    void MyFunction(B argument);
    #endif
    

    When I try expanding out the #include "B.h", I get this:

    // File: A.h
    #ifndef A_Included
    #define A_Included
    
    // File: B.h
    #ifndef B_Included
    #define B_Included
    
    #include "A.h"
    
    class B {};
    
    void MyOtherFunction(A argument);
    #endif
    
    class A {};
    
    void MyFunction(B argument);
    #endif
    

    At this point, the preprocessor will again try expanding out A.h, which leads to this:

    // File: A.h
    #ifndef A_Included
    #define A_Included
    
    // File: B.h
    #ifndef B_Included
    #define B_Included
    
    // File: A.h
    #ifndef A_Included
    #define A_Included
    
    #include "B.h"
    
    class A {};
    
    void MyFunction(B argument);
    #endif
    
    class B {};
    
    void MyOtherFunction(A argument);
    #endif
    
    class A {};
    
    void MyFunction(B argument);
    #endif
    

    Now, let’s see what happens when we resolve all of these weird include guards. The first time we see A, it’s expanded out, as is the case when we expand out B for the first time. However, when we see A for the second time, it’s not expanded out at all. Thus, after taking out comments and preprocessor directives, we get this resulting code:

    class B {};
    void MyOtherFunction(A argument);
    class A {};
    void MyFunction(B argument);
    

    Notice that when MyOtherFunction is declared, A has not yet been declared, and so the compiler reports an error.

    To fix this, you can forward-declare A and B in the header files that need them:

    // File: A.h
    #ifndef A_Included
    #define A_Included
    
    class A {};
    class B;    // Forward declaration
    
    void MyFunction(B argument);
    #endif
    

    and

    // File: B.h
    #ifndef B_Included
    #define B_Included
    
    class B {};
    class A;    // Forward declaration
    
    void MyFunction(B argument);
    #endif
    

    Now, there are no more circular dependencies. As long as you #include the appropriate header files in the .cpp files, you should be fine.

    Hope this helps!

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

Sidebar

Related Questions

I strongly expect this to end up as a duplication, but I can't seem
I am new to doing this sort of thing but I would like to
For some reason this sort code is not working as I would expect: std::fstream
Sort of a methods/best practices question here that I am sure has been addressed,
I sort of understand this, at least the function of generators (I've used them
i want to sort dictionary based upon value of each dictioanry item.but if i
The recursion is sort of a 'divide and conquer' style, it splits up while
This has been an age old question and I am aware of the usual
This works quite well in 1 dimension: # This will sort bar by the
Given the test case below how can I: Sort the IList<TestObject> based on the

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.