Recently I am having many problem with typedef and incomplete type when I changed certain containers, allocators in my code.
What I had previously
st
Compiller doesn't know the size of incomplete type, therefore it can not instantiate it nor allocate some memory for it. Having a pointer to object (like typedef std::tr1::array<foo*, 5> all_foos;
) instead of instance of the object itself solves this issue.
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.