Victor Bazarov wrote in
news:FG3nd.11112$Ae.1903@newsread1.dllstx09.us.to. verio.net in
comp.lang.c++:
[color=blue]
>
uvts_cvs@yahoo.com wrote:[color=green]
>> template <class T>
>> class foo
>> {
>> public:
>> template <class Tin>
>> T bar (Tin) {return T();}
>> };
>>
>> class derived : public foo<derived>
>> {
>> };
>>
>> Some compilers compile successfully, while another tells me that I'm
>> using the undefined class 'derived'.
>>
>> Is this little chunk of code compliant with the ISO C++ standard or
>> not?[/color]
>
> It probably is in that grey area, you know, twilight zone, where
> all the templates live before they pop up into our minds...
>
> The code is compliant. By the time you get around to initialising
> a 'derived' object, the class 'derived' and therefore its base class
> 'foo<derived>' will have been completely defined. The compilers that
> can't handle that kind of code aren't sophisticated enough to delay
> generating of the code until it's actually needed.
>
> Of course, you could have written
>
> class derived : public foo<derived>
> {
> derived fubar() {
> return foo<derived>::template bar(42);
> }
> };
>
> which would cause an attempt to use 'foo<derived>' _before_ 'derived'
> was completely defined. In that case the work-around is to place the
> body of 'derived::fubar' outside the class definition.
>[/color]
I tried it and the workaround wasn't needed, however with VC 7.1,
which exhibits the original problem, moving the member defenition
out of foo was required:
template < typename T > template < typename Tin >
T foo< T >::bar( Tin )
{
return T();
}
Incresing I'm thinking that MSVC 7.1 is pants.
Rob.
--
http://www.victim-prime.dsl.pipex.com/