1

これが機能しない理由を誰でも説明できますか:

#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>*)
*/

これらのクラス テンプレートの定義は次のとおりです。 http://www.itk.org/Doxygen/html/classitk_1_1CovariantVector.html http://www.itk.org/Doxygen/html/classitk_1_1Image.html

非 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);
  delete image;
  return 0;
}

誰が違いを説明できますか?

4

1 に答える 1

0

問題は、署名を から に変更して<int NumberOfComponents><unsigned int NumberOfComponents>ITK クラスの定義と一致させなければならなかったことです。

#include <iostream>

template <typename TPixel, int Dimensions>
struct Image
{
};

// The deduction works with this
// template <typename TComponent, int NumberOfComponents>
// struct Vector
// {
// };

// The deduction does NOT work with this (unsigned int vs int above)
template <typename TComponent, unsigned 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;
}
于 2012-07-31T20:44:03.960 に答える