[Insight-users] Template functions

David Doria daviddoria at gmail.com
Mon Nov 1 16:25:56 EDT 2010


If I template a function on T and T is a itk::Image<unsigned
char>::Pointer, all is well (as below):

class Test
{
  public:
  template <class T>
  void Add(T patch);
};

template <class T>
void Test::Add(T patch)
{

}

int main(int, char*[])
{
  Test a;
  itk::Image<unsigned char>::Pointer image;
  a.Add(image);
  return EXIT_SUCCESS;
}

However, if I template the function on T::Pointer where T is
itk::Image<unsigned char>, I get errors. I even tried to explicitly
instantiate the template:

#include <itkImage.h>

class Test
{
  public:
  template <class T>
  void Add(typename T::Pointer patch);
};

template <class T>
void Test::Add(typename T::Pointer patch)
{

}

template void Test::Add(itk::Image<unsigned char>::Pointer); // instantiate

int main(int, char*[])
{
  Test a;
  itk::Image<unsigned char>::Pointer image;
  a.Add(image);
  return EXIT_SUCCESS;
}

error: template-id ‘Add<>’ for ‘void
Test::Add(itk::SmartPointer<itk::Image<unsigned char, 2u> >)’ does not
match any template declaration
error: no matching function for call to
‘Test::Add(itk::SmartPointer<itk::Image<unsigned char, 2u> >&)’

I see that this is done all over ITK, but I can't figure out why it
won't work here. Any ideas?

Thanks,

David


More information about the Insight-users mailing list