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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:49:04+00:00 2026-06-09T09:49:04+00:00

How can I solve the following circular dependency? typedef boost::variant<int, bool, double, std::string, Structure>

  • 0

How can I solve the following circular dependency?

typedef boost::variant<int, bool, double, std::string, Structure> Value;
typedef std::list<std::pair<std::string, ValueContainer>> Structure;
typedef std::vector<Value> ValueContainer;

I’m attempting to represent objects from a C api database library in a more C++ form. This database allows one to store values or arrays of values, as well as having a representation for Structures, as follows:

typedef struct ApiStructureMember 
{
    char* name;
    struct ApiValueContainer value;
    struct ApiStructureMember_T* next;
} ApiStructureMember_T;

Finally, a union is used to represent a value, as follows:

typedef struct ApiValue 
{
    union 
    {
        int i;
        const char*   s;
        ...
        struct ApiStructureMember_T* firstStructureMember;
    } value;
} ApiValue_T; 
  • 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-09T09:49:06+00:00Added an answer on June 9, 2026 at 9:49 am

    You can’t have types mutually containing each other. Think about it: the compiler would get into an infinite loop generating the data.

    There are two general patterns: the first is through data types pointing to each other

    struct OddNode; // forward declaration
    
    struct EvenNode 
    {
        OddNode* prev;
        OddNode* next;
    };
    
    struct OddNode
    {
        EvenNode* prev;
        EvenNode* next;
    };
    

    If you leave away the pointers, and implement the Even and Odd nodes with containment by value, then the compiler can never resolve the definitions.

    In general: just draw a picture of how you want to lay out the data, with boxes representing data and lines connecting the various parts. Then replace each box with a class, and each line with a pointer to the corresponding class. If you have a circular dependency somewhere, simply forward declare the classes at the top of your code.

    The second circular dependency is through the Curiously Recurring Template Parameter (CRTP)

    template<typename T> 
    struct Y 
    {};
    
    struct X
    : 
        public Y<X> 
    {};
    

    Your example would be using the CRTP with Structure as X and std::list< ..., Structure> as Y<X>.

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

Sidebar

Related Questions

Can any one tell me how to solve the following scenario in Asp.net application.
i wonder how i can solve the following problem. i have a horizontal scrollbar
i wonder how i can solve the following problem: I'm reading a folder on
How can i solve the following (simplified) problem? M-V-VM context. I want to show
I'm not a javascript professional so I can't solve the following code alone. I
I was wondering if someone can help me solve the following problem. Someone has
How can you solve the following error messages given by PHPdoc? I run madedoc.sh
does anyone know how I can solve the following problem. I want to return
How can you solve the following encoding problem? http://dl.getdropbox.com/u/175564/encoding.png It is rather hard to
I know I can solve the following problem just by creating a custom class,

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.