[Insight-users] Template deduction failing with ITK classes but non an identical non-ITK demo
David Doria
daviddoria at gmail.com
Fri Jul 27 19:46:49 EDT 2012
On Fri, Jul 27, 2012 at 4:13 PM, David Doria <daviddoria at gmail.com> wrote:
> Can anyone explain why this doesn't work:
>
> #include "itkCovariantVector.h"
> #include "itkImage.h"
>
> template <typename TComponent, int NumberOfComponents>
> void FillImage(itk::Image<itk::CovariantVector<TComponent,
> NumberOfComponents>, 2>* const image,
> itk::Image<itk::CovariantVector<TComponent,
> NumberOfComponents>, 2>* const output)
> {
> std::cout << "Works." << std::endl;
> }
>
> int main(int, char* [] )
> {
> typedef itk::Image<itk::CovariantVector<float, 3u>, 2u> ImageType;
>
> ImageType::Pointer imageSmartPointer = ImageType::New();
> ImageType* image = imageSmartPointer.GetPointer();
> FillImage(image, image);
> return 0;
> }
> /*
> no matching function for call to ‘FillImage(ImageType*&, ImageType*&)’
> note: candidate is:
> template<class TComponent, int NumberOfComponents> void
> FillImage(itk::Image<itk::CovariantVector<TComponent,
> NumberOfComponents>, 2u>*, itk::Image<itk::CovariantVector<TComponent,
> NumberOfComponents>, 2u>*)
> */
>
>
> -----------------
> but this works fine (non-ITK):
>
> #include <iostream>
>
> template <typename TPixel, int Dimensions>
> struct Image
> {
> };
>
> template <typename TComponent, int NumberOfComponents>
> struct Vector
> {
> };
>
> template <typename TComponent, int NumberOfComponents>
> void FillImage(Image<Vector<TComponent, NumberOfComponents>, 2 >* const image,
> Image<Vector<TComponent, NumberOfComponents>, 2 >* const output)
> {
> std::cout << "Works." << std::endl;
> }
>
> int main(int, char* [] )
> {
> typedef Image<Vector<float, 3>, 2 > ImageType;
>
> ImageType* image = new ImageType;
> FillImage(image, image);
> return 0;
> }
>
> I tried to reproduce the same thing, just with non ITK classes, and it
> works, but the ITK version does not?
>
> David
Ah, I figured it out. I had to change
template <typename TComponent, int NumberOfComponents>
to
template <typename TComponent, unsigned int NumberOfComponents>
so that it matched the itk::CovariantVector template parameters exactly.
David
More information about the Insight-users
mailing list