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;
}
誰能解釋可能是什麼區別?
可能是一個愚蠢的問題:爲什麼函數匹配前面有'template template '? –
2012-07-27 19:54:03
你還可以發佈簽名itk :: Image,2> :: GetPointer()? –
2012-07-27 20:01:07
模板是因爲函數模板在類模板中。 ImageType :: Pointer是一個智能指針。 imageSmartPointer.GetPointer()返回一個正常的ImageType *。 –
2012-07-27 20:02:33