Topic: Another typename query
Author: bparker@gil.com.au (Brian Parker)
Date: 1997/04/13 Raw View
Alexandre Oliva <oliva@dcc.unicamp.br> wrote:
>Brian Parker writes:
>> Can anyone please tell me whether the typenames in the following
>> example are required, or are, in fact, disallowed?
>> template<class T>
>> void Func(T t ){
>> return Func2<typename T::type_nontype>( Traits<typename T::type>() );
>> }
>It must be decided at the declaration point whether T::type_nontype
>and T::type name a type or a value, so the keyword typename is
>required if you're supposed to refer to a type, and required not to be
>present if you're referring to a non-type.
Thanks for your response, I suppose I will send this example off as a
VC 5.0 bug report.
BTW, here is another minor example I didn't include in the original
posting-
template<class T, class i =T::i>
class C {};
Clearly the T::i above doesn't need a "typename" qualification and I
am pretty sure the draft doesn't intend for one to be used, but the
wording of 14.6 [temp.res] suggests it is required.
Anyone have any thoughts on this example?
,Brian Parker (bparker@gil.com.au)
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: bparker@gil.com.au (Brian Parker)
Date: 1997/04/08 Raw View
Greetings all,
I have recently been randomly sprinkling "typename" throughout my code
and have come across another example where I am uncertain as to
whether it is required or not.
Can anyone please tell me whether the typenames in the following
example are required, or are, in fact, disallowed?
template<class T>
void Func(T t ){
return Func2<typename T::type_nontype>( Traits<typename T::type>() );
}
Func2 may have valid instantiations regardless of whether
T::type_nontype is a type or a non-type and so I presume that typename
would be optional here, or will the compiler complain if I use
typename but later T::type_nontype turns out to be a non-type.
For T::type, is the compiler supposed to check Traits<> to ensure that
it takes a type parameter, or must the compiler accept the code
regardless.
Visual C++ 5.0 disallows both typenames.
,Brian Parker (bparker@gil.com.au)
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1997/04/08 Raw View
Brian Parker writes:
> Can anyone please tell me whether the typenames in the following
> example are required, or are, in fact, disallowed?
> template<class T>
> void Func(T t ){
> return Func2<typename T::type_nontype>( Traits<typename T::type>() );
> }
It must be decided at the declaration point whether T::type_nontype
and T::type name a type or a value, so the keyword typename is
required if you're supposed to refer to a type, and required not to be
present if you're referring to a non-type.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
Universidade Estadual de Campinas, SP, Brasil
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]