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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:46:51+00:00 2026-06-13T17:46:51+00:00

This code: class Foo { std::unordered_map<std::string, Foo> x; }; gives me an error: /usr/include/c++/4.7/bits/stl_pair.h:94:11:

  • 0

This code:

class Foo {
    std::unordered_map<std::string, Foo> x;
};

gives me an error:

/usr/include/c++/4.7/bits/stl_pair.h:94:11:
  error: 'std::pair<_T1, _T2>::second' has incomplete type
foo.cpp:4:7: error: forward declaration of 'class Foo'

However, this code compiles just fine:

class Foo {
    std::vector<Foo> x;
};

Is this a library/compiler bug?

  • 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-13T17:46:53+00:00Added an answer on June 13, 2026 at 5:46 pm

    The C++ standard specifies for the various smart pointers that the template parameter is allowed to be an incomplete type.

    The 2017 and later versions of the standard allow a container’s value_type to be an incomplete type when instantiating the class template only for the container templates std::forward_list, std::list, and std::vector, and only if the allocator type satisfies the "allocator completeness requirements". The default allocator template std::allocator always satisfies the allocator completeness requirements. Instantiating any member of the container class template still requires the value_type to be complete.

    For any other standard container type, this information is not given. In cases where it is unspecified, an implementation is allowed to accept an incomplete type for one container class template and not another, and still be conformant.

    To make your code portable, avoid making containers of any type before the type is completed, except in the cases specifically permitted by the standard.

    Formally, the general constraint is found in the following rule ([res.on.functions]) which applies to your code:

    In certain cases (replacement functions, handler functions, operations on types used to instantiate standard library template components), the C++ standard library depends on components supplied by a C++ program. If these components do not meet their requirements, the Standard places no requirements on the implementation.

    In particular, the effects are undefined in the following cases:

    …

    • if an incomplete type is used as a template argument when instantiating a template component, unless specifically allowed for that component.

    The three statements specifically allowing an incomplete template argument for forward_list, list, and vector are found in sections [forwardlist.overview], [list.overview], and [vector.overview].

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

Sidebar

Related Questions

The following code does not compile: #include <iostream> class Foo { std::string s; public:
Given this code: #include <iostream> using namespace std; class Foo { public: Foo ()
I have this code: #include <iostream> using namespace std; class FooA { public: virtual
I have this code: #include <iostream> class foo { public: foo(int yy){y = yy;}
Imagine this code: class foo { foo fff; int m_id; f & work() {
In this code: <?php class Foo { var $value; function foo($value) { $this->setValue($value); }
take this simple code: class A{ public: virtual void foo() = 0; void x(){
Consider this code : class MyClass<T> { } class AnotherClass : MyClass<String> { }
I have this code: class MyObj { int Id; string Name; string Location; }
First look at this code: class Program { static void Main(string[] args) { var

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.