[Insight-developers] typename

Bill Hoffman bill.hoffman at kitware.com
Tue Sep 5 10:26:50 EDT 2000


Hi all,

The Microsoft compiler seems to be a bit lax on requiring the key word
typename.    However, the SGI and gcc are not.  The basic rule to
follow is this:

If you have a template parameter or template derived parameter and
you use :: on the type, then it needs typename.

Here are some examples:

template <class T, class TOutputImage>
foo()
{
  T a;                     // OK
  T::FooType b;            // ERROR
  typename T::FooType;     // OK
  T::Pointer p;            // ERROR
  typename T::Pointer p;   // OK
  typedef typename TOutputImage::ScalarValueType scalar;  // OK
  typedef  TOutputImage::ScalarValueType scalar;          // ERROR
}

If the type is used more than once in a class, then a class scope
typedef with the correct typename would be a good idea.
(See itkMesh.h, you can see typename is only used with
typedefs that have a :: in them.)


-Bill





More information about the Insight-developers mailing list