[Insight-users] OT: Generic Programming - Typedefs inside
template functions
Peter Cech
pcech at vision.ee.ethz.ch
Mon Jan 8 05:42:38 EST 2007
On Sun, Jan 07, 2007 at 21:02:41 -0300, Wagner Sales wrote:
> Dears,
>
> May be that's a fool question, but I'm not so familiar with templates and my searches are returned not useful.
>
> Well, I'm trying to give some type at a template function and use them to define the image type. My method are:
>
> template <typename T>
> void MyFilter::processImage(T)
> {
> if(!m_ImageData) return;
> // defines the type
> typedef T PixelType;
> typedef itk::Image<T, 3> ImageData;
> ImageData::Pointer m_Image = ImageData::New();
You have to use typename:
typename ImageData::Pointer m_Image = ImageData::New();
This is because ImageData is derived from a template parameter of the
method (or a class that method is a member of). Whenever you want to use
a typedef from inside of such type, you have to explicitly tell the
compiler it is a type ("typename DerivedType::TypedefedType"). Without
"typename" compiler is treating the construct as a member variable.
> typedef itk::ImageToVTKImageFilter< ImageData > ToVTKConverter;
> typedef itk::VTKImageToImageFilter< ImageData > ToITKConverter;
> typedef itk::BinaryThresholdImageFilter<ImageData, ImageData> FilterType;
> ToVTKConverter::Pointer m_toVTKConverter = ToVTKConverter::New();
typename ToVTKConverter::Pointer m_toVTKConverter = ToVTKConverter::New();
> ToITKConverter::Pointer m_toITKConverter = ToITKConverter::New();
typename ToITKConverter::Pointer m_toITKConverter = ToITKConverter::New();
> FilterType::Pointer m_Filter = FilterType::New();
typename FilterType::Pointer m_Filter = FilterType::New();
> .
> .
> and so on...
and so on...
Regards,
Peter Cech
More information about the Insight-users
mailing list