Re: Incomplete type as template argument

From: John Carson (donaldquixote_at_datafast.net.au)
Date: 02/25/04


Date: Wed, 25 Feb 2004 18:21:08 +1100


"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:g5W_b.54098$Xp.257962@attbi_s54
> "Andrew Ward" <anwar@ihug.co.nz> wrote...
>> Hi All,
>>
>> Considering the following code:
>>
>> struct A;
>>
>> struct B
>> {
>> std::list<A> l;
>
> Neither 'std' nor 'list' is defined.
>
>> };
>>
>> void foo()
>> {
>> B b;
>> };
>>
>> struct A
>> {
>> int x;
>> };
>>
>> int main()
>> {
>> foo();
>> A a;
>> a.x = 22;
>> B b;
>> b.l.push_back(a);
>> cout << "A's value = " << b.l.begin()->x << endl;
>> }
>>
>> I do not understand why the compiler does not complain when
>> encountered with std::list<A> when A has not been fully defined.
>
> I do not understand either. Comeau C++ does complain.
>
>> Could someone please explain to me when the compiler actually does
>> the template expansion, and is this method of using incomplete types
>> as template arguments safe for all compliant compilers?
>
> You should probably ask whoever made your compiler. They must hold
> the secret of how to use an incomplete type as a template argument...
>
> Victor

I don't claim to understand all the subtleties of this matter but... section
14.3.1 p2 of the 2003 standard says:

"[Note: a template type argument may be an incomplete type (3.9). ]"

-- 
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)


Relevant Pages

  • Pointer-to-member-function as template parameter - strange error, plus an ICE
    ... Here's some code that makes the VC8 compiler do interesting things. ... template <class C, typename Sig> ... template ... struct Func ...
    (microsoft.public.vc.language)
  • Re: trait technique?
    ... On Sat, 18 Dec 2004, Victor Bazarov wrote: ... the template? ... struct type: typeClass ... static string name; ...
    (comp.lang.cpp)
  • Some issues with using sizeof() in template definitions
    ... I have two issues with VC++, which might or might not be related, but both have to do with using the sizeof inside template definitions. ... When using sizeof inside my allocator, such as to assign to an enum value defined in the class, the compiler complains about errors in. ... templatestruct MemberCheck ...
    (microsoft.public.vc.language)
  • Re: Incomplete type as template argument
    ... > struct A; ... > void foo() ... > and is this method of using incomplete types as template arguments safe ... You should probably ask whoever made your compiler. ...
    (comp.lang.cpp)
  • possible compiler bug?
    ... I have a template class that instantiates a variable of the template ... struct TemplateClass ... struct TestClass ... it compiles fine under the Borland compiler. ...
    (comp.lang.cpp)