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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:01:05+00:00 2026-06-14T14:01:05+00:00

I was confused about how I would create two structs that reference each other.

  • 0

I was confused about how I would create two structs that reference each other. I couldn’t find any question like it asked before.
So, I know that this will compile just fine:

    struct MyStruct {
        MyStruct* p;
    };

But, for instance,

    struct A {
        B* pBstruct;
    };
    struct B {
        A* pAstruct;
    };

This won’t compile.

  • 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-14T14:01:07+00:00Added an answer on June 14, 2026 at 2:01 pm

    So, I know I asked it, but I figured it out and thought that answering it might help others.

    Just like making recursive functions, structures must also be prototyped.
    So, consider making recursive functions:

        int fnc_a();
        int fnc_b();
    
        int fnc_a()
        {
            fnc_b();
        }
        int fnc_b()
        {
            fnc_a();
        }
    

    The first two lines identify as the prototypes for the functions so that they can be used before their actual definition/declaration is provided.
    Now consider making two recursive structs again:

        struct A;
        struct B;
        struct A {
            B* pBstruct;
        };
        struct B {
            A* pAstruct;
        };
    

    These first two lines declare the existence of the two structs so that they can be used before they are declared. (Don’t bother commenting on the fact I only need the B struct prototype – I do recognize that)

    One final note, don’t forget to use struct ‘pointer’ variables and not struct variables. This will not compile because it would create an infinitely large structure:

        struct A;
        struct B;
        struct A {
            B pBstruct;
        };
        struct B {
            A pAstruct;
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am rather confused about how this would be possible with the iOS Sandbox,
I am a little confused about Accept-Encoding . I have Web Service which would
The first thing i would like to say is that this is not exactly
I have a web app of which I would like to create a mobile
I'm pretty confused on how to go about this. Say I have two columns
I am a little confused about the roles of a java application server and
I'm a bit confused about the size of my App! The folder and all
I am a bit confused about the 'rules' of when a TextView element displays
I'm a little confused about something. I wrote an app and tested it on
I'm a little confused about the HTTP protocol, from what i know HTTP was

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.