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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:28:51+00:00 2026-05-15T09:28:51+00:00

Recently I am having many problem with typedef and incomplete type when I changed

  • 0

Recently I am having many problem with typedef and incomplete type when I changed certain containers, allocators in my code.

What I had previously

struct foo;//incomplete type.
typedef std::vector<foo> all_foos;
typedef all_foos::reference foo_ref;

Though not completely not sure whether the above lines are legal, but this worked on every implementation I used. When I thought that I can do the job with std::tr1::array, changed the above two lines with

typedef std::tr1::array<foo,5> all_foos;
typedef all_foos::reference foo_ref;

Here everything breaks, as the compiler tries to instantiate array and fails as foo is incomplete type. What all I needed is a reference to foo, and not much interested on ‘other parts’ of the array. foo will definitely be completely available when I create such an array.

The same is problem when typedef std::allocator<foo>::pointer foo_ptr got replaced by typedef stack_alloc<foo,10>::pointer foo_ptr. where a stack_alloc implementation is like

template<typename T,unsigned N>
struct stack_alloc
{
  typedef T* pointer;
  typedef std::tr1::aligned_storage<sizeof(T)*N, std::tr1::alignment_of<T>::value> buffer;
};

Presuming that, value_type, pointer, reference, iterator etc does not depend on the completeness of T, and knowing that the class can not be instantiate without complete type, how such typedef can be made in generic way independent of specific container or allocator?

NOTE:

  • Just for completeness, in ‘real’ code I use a small local memory with vector rather than replacing it with std::array, though the problem remains same.
  • stack_alloc code is far from complete, and only shows the part of the problem.
  • I know that array, sizeof etc needs complete type available. But I am NOT creating object of type all_foos with incomplete foo.
  • My assertion is that pointer,reference etc should not depend on completeness of a type. Otherwise construct like struct foo{ foo_ptr p;}; can not be defined. Though probably foo_ref can not be anything other than foo&, but foo_ptr can be. Surprisingly GCC implementation doesn’t have nested pointer type for tr1::array.
  • Know mostly what can not be done, and interested to know what can be done in this situation. So expecting a good design as a solution.
  • 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-05-15T09:28:52+00:00Added an answer on May 15, 2026 at 9:28 am

    A type must be complete to be used in a standard container, or the behavior is undefined (§17​.4.3.6/2). So the only standard solution is to not make that typedef until the class is defined.

    I don’t get what the intermediate container is for:

    struct foo;//incomplete type.
    typedef foo& foo_ref;
    

    In any case, you’ll just have to have the complete type defined first, really. To get a typedef defined in a class, that class must be instantiated, which means the entire thing must be able to use T as desired.

    For example, stack_alloc must have T be a complete type (for sizeof(T) to work), otherwise the class cannot be instantiated. If the class can’t be instantiated, you cannot get the typedef out of it. Ergo, you’ll never get the typedef out of it if T is incomplete.

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

Sidebar

Related Questions

I'm using SQL Server 2008 and just recently started having an intermittent problem while
Having recently learned of the DebuggerDisplay attribute, I've found it quite useful. However, one
Having recently discovered design patterns, and having acquired the excellent Head First Design Patterns
Having recently seen a presentation of Clojure Protocols, I was quite impressed by the
I've recently been having some issues with some tooltips on a webpage not displaying
I've recently started having trouble logging into my site using Facebook. I keep seeing
I am currently using ASP.NET MVC 2.0 RC2, having recently moved from version 1.0.
Recently I was having some issues with a singelton class that was lazy initializing
Recently I was having a discussion with a friend about Ruby's Proc . You
Having made the jump just recently from XEmacs to GNU Emacs, I'm really loving

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.