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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:27:22+00:00 2026-06-08T00:27:22+00:00

Simple question: How do I get this to work? struct A { double whatever;

  • 0

Simple question: How do I get this to work?

struct A {
    double whatever; 
    std::unordered_map<std::string, A> mapToMoreA; 
}

g++ error: std::pair<_T1, _T2>::second has incomplete type

As far as I understand, when instantiating the map, the compiler needs to know the size of A, but it doesn’t know this because the map is declared in A’s declaration, so is the only way to get around this to use pointers to A (don’t feel like doing that)?

  • 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-08T00:27:24+00:00Added an answer on June 8, 2026 at 12:27 am

    Most of the time it will depend on the container implementation details (more precisely, on what gets instantiated at the point of container declaration and what doesn’t). Apparently, std::unordered_map implementation requires the types to be complete. At the same time GCC’s implementation of std::map compiles perfectly fine with incomplete type.

    To illustrate the source of such difference, consider the following example. Let’s say we decided to make our own naive implementation of std::vector-like functionality and declared our vector class as follows

    template <typename T> class my_vector {
      T *begin;
      T *end;
      ...
    };
    

    As long as our class definition contains only pointers to T, the type T is not required to be complete for the class definition itself. We can instantiate my_vector itself for an incomplete T without any problems

    class X;
    my_vector<X> v; // OK
    

    The “completeness” of the type would be required later, when we begin to use (and therefore instantiate) the individual methods of my_vector.

    However, if for some reason we decide to include a direct instance of T into our vector class, things will chahge

    template <typename T>
    class my_vector {
      T *begin;
      T *end;
      T dummy_element;
      ...
    };
    

    Now the completeness of T will be required very early, at the point of instantiation of my_vector itself

    class X;
    my_vector<X> v; // ERROR, incomplete type
    

    Something like that must be happening in your case. The definition of unordered_map you are dealing with somehow contains a direct instance of A. Which is the reason why it is impossible to instantiate (obviously, you would end up with infinitely recursive type in that case).

    A better thought through implementation of unordered_map would make sure not to include A into itself as a direct member. Such implementation would not require A to be complete. As you noted yourself, Boost’s implementation of unordered_map is designed better in this regard.

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

Sidebar

Related Questions

This should be a simple question, but I can't get it to work :(
This is a simple question: Is this a correct way to get an integer
This is a very simple question for compiler guys, but I always get confused
This is a really simple question. Is it possible for jQuery to get an
Ok this is embarrassingly simple of a question, but I just can't get this
This is a really simple question about CSS. I want to get the style
Alright, I know this is a simple question, but I can't seem to get
Simple question, I should think. Unfortunately, I couldn't figure out how to get it
Probably a simple question: Why do I get an compiler warning for the following
i have a simple question in the objectify documentation it says that Only get(),

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.