[Insight-users] using typename (fwd)

Bing Jian bjian at cise . ufl . edu
Tue, 18 Nov 2003 14:17:09 -0500 (EST)


---------- Forwarded message ----------
Date: Mon, 17 Nov 2003 23:13:41 -0500 (EST)
From: Bing Jian <bjian at cise . ufl . edu>
To: Benjamin King <king . benjamin at mh-hannover . de>
Subject: Re: [Insight-users] using typename

Hi Benjamin,

  Thanks! Your comment is very helpful.

  And I want to let you know I just figured out one point that
confused me before :-)

  In one member function of Class T, I have
  void fun()
  {
     SomeTypeSpec variable;    //(*)
     ...

  }
  One thing I felt confusing is :
   If without typename in (*), g++ will give warning of
"implicit typename".
   but if I use typename, g++ will give error.

  However, I got to know the reason: because the SomeTypeSpec is
defined by "typedef typename" in T's superclass, but not mentioned
in class T. So one solution is to add one single in T.h

   typedef typename SuperClass::SomeTypeSpec SomeTypeSpec.

 or use SuperClass::SomeTypeSpec.

   Have a nice day!

-- 
Best wishes,
Bing Jian
bjian at cise . ufl . edu


On Mon, 17 Nov 2003, Benjamin King wrote:

> Hi Bing,
>
> g++ requires the use of the typename keyword only in the context of
> templates and complains if you use it anywhere else. And in a template's
> context, you have to use it when you access a template's member that is a
> type:
>
> template <class T>
> void twiddle()
> {
> 	// use of 'typename' optional but omitting it gives
> 	// 'implicit typename deprecated' warnings
> 	typename T::SomeTypeSpec variable;
>
> 	// No need for typename as we don't access a type.
> 	variable = T::SomeStaticPublicMember;
>
> 	// A practical example where you need 'typename's all the time
> 	typedef itk::Image<typename T::PixelType, 3> myImageType;
> }
>
> I think that's all there is to know but I'm no authority on that =)
>
> cheers,
>   Benjamin
>
> On Sat, 15 Nov 2003 20:52:01 -0500 (EST), Bing Jian <bjian at cise . ufl . edu>
> wrote:
>
> > Hi,
> > It's an another C++ issue about usage of typename.
> > I write and debug my ITK program in visual studio, but
> > finally I have to move it to Sun and Linux, then compile
> > the code using g++. Seems g++ is always complaining
> > about my usage of typename. I have to add typename
> > at some places and remove typename at other locations.
> > Even the program finally compiles, I get lots of warnings
> > like
> > warning: implicit typename is deprecated
> > Do you guys have any experience on that? Thanks!
> >
> >
>
>
>
>