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 7802895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:23:45+00:00 2026-06-02T01:23:45+00:00

Hi i have two classes A and B . in A i am using

  • 0

Hi i have two classes A and B .
in A i am using the header file for B so that i can create an instance for B( e.g. B *b ) and the something i am doing in Class B also i.e including the header file of A and creating the instance for A(e.g. A *a) in B .

while i am including the header file for A in B it gives me the following error in A.h

1>c:\Bibek\A.h(150) : error C2143: syntax error : missing ';' before '*'
1>c:\Bibek\A.h(150)(150) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\Bibek\A.h(150)(150) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
  • 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-06-02T01:23:46+00:00Added an answer on June 2, 2026 at 1:23 am

    It sounds like you are including the header files in a circular manner (A.h includes B.h, which includes A.h). Using header guards means that when B.h includes A.h in the above scenario, it skips that (due to the now active include guard of A.h), so the types in A.h are not yet defined when parsing B.h.

    To fix, you can use forward declarations:

    // A.h
    #ifndef A_H
    #define A_H
    
    // no #include "B.h"
    
    class B; // forward declaration of B
    class A {
      B* b;
    };
    
    #endif
    

    similarly for B.h

    This allows you to use pointers of the forward declared class (e.g. in declarations of member variables, member function declarations), but not use it in any other way in the header.

    Then in A.cpp you need to have the proper definition of B.h, so you include it:

    // A.cpp
    
    #include "A.h"
    #include "B.h" // get the proper definition of B
    
    // external definitions of A's member functions
    

    This construction avoids the circular inclusion of the header files while allowing full use of the types (in the .cpp files).

    Note: the error about the non-support of default int happens as the compiler does not have the proper definition of A when including B.h, (the C language allows default int definition for unknown types, but this is not allowed in C++)

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

Sidebar

Related Questions

I have two classes. I created a JAR file using: jar cvf practice.jar class1.class
I am trying to serialize/deserialize JSON in Android using GSON. I have two classes
I have two classes which need to be in same xml file. The way
I have two classes: class Translation(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() object =
I have two classes defined like public class PostleitzahlList : ObservableCollection<Postleitzahl> { } public
I have two classes declared in C# code: public class A { public static
I have two classes: public class CourseModule { // attributes... List<Course> courses; public void
I have two classes in a different projects. I am importing the project that
I have two classes: testClass and castClass : class testClass { public: int field1;
I have two classes, one nested in the other. Public Class Operation Public Property

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.