help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: G++ 3 and typename warnings


From: Guy Harrison
Subject: Re: G++ 3 and typename warnings
Date: Wed, 15 Sep 2004 19:00:03 GMT
User-agent: KNode/0.7.7

Shane Walton wrote:

> I am having a hard time understanding this code, so I hope cutting it
> down to 256 lines minus line numbers will help.  I have also listed
> the warning output that I am trying to prevent.  Thanks again for the
> help.

This is actually a comp.lang.c++ question. Consider...

template <typename T> struct foo {
typedef T TT;
};

template <typename T> struct bar {
 bar()
        #if 1
 {for (foo<T>::TT i = 0; i < 10; i++);}
        #else
 {for (typename foo<T>::TT i = 0; i < 10; i++);}
        #endif
};

[snip]

>Callback.hh: In constructor
>  `CBFunctionTranslator1<P1, Func>::CBFunctionTranslator1(Func)':
>Callback.hh:95: warning:
>  `CBFunctionTranslator1<P1, Func>::PFunc' is implicitly a typename
>
>CBFunctionTranslator1(Func f):CBFunctor1<P1>(thunk,0,(PFunc)f,0,0){} 

Thus...

(PFunc)f

...becomes...

(typename PFunc)f

...but you've got "old" code there. Sometimes the "old" C style casting is
appropriate but if in doubt do it the C++ way...

static_cast<typename CBFunctor1<P1>::PFunc>(f)

Contrast with...

static_cast<CBFunctorBase::PFunc>(f),0,0){}

I'm not saying the latter is correct (designwise) but once you've
visited/lurked comp.lang.c++ it'll be apparent why the former needs
"typename" whilst the latter does not.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]