Old Wolf wrote in news: om in
comp.lang.c++:
> tom_usenet <> wrote:
>>
>> 2 In particular, the effects are undefined in the following cases:
>> [snip]
>> ? if an incomplete type (3.9) is used as a template argument when
>> instantiating a template component.
>
> I think I am confused about the meaning of "instantiating"?
Its when a template (class or function) is used to create a new
type or function (a specialization in standardeze).
>
>> #include <list>
>>
>> template<typename T>
>> struct Tree
>> {
>> std::list< Tree<T> > child;
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> declaration (no objects are yet created)
Correct, and the declaration isn't the problem.
>
>> };
>>
>> int main()
>> {
>> Tree<int> bar;
> ^^^^^^^^^^^^^^
> instantiation (a 'Tree<int>' object is created, which involves
> creation of any sub-objects of Tree<int>).
Yes, however the type "Tree< int >" isn't *complete* until
instantiation is finnished.
> Surely at this point, Tree<int> is a complete type,
> so std::list< Tree<int> > would be OK.
Yes, but instantiating Tree< int > requires that Tree< int >
be *complete* before Tree< int > is instantiated, a catch 22,
as a template isn't complete until its been instantiated.
>
>> std::list< Tree<int> > foo;
>> foo.push_back(bar);
>> }
>
Note: with class templates "complete" and "instantiated" are
equvalent terms, however non-templates can also be incomplete:
struct X; /* incomplete */
struct x {}; /* complete */
Rob.
--
http://www.victim-prime.dsl.pipex.com/