次のコードでは:
#include "itkImage.h"
#include "itkImageRegionIterator.h"
struct CustomImageBase
{
virtual void DoSomething() = 0;
};
template <typename TPixel>
struct CustomImage : public itk::Image<TPixel, 2>, public CustomImageBase
{
void DoSomething()
{
itk::Index<2> index;
index.Fill(0);
std::cout << this->GetPixel(index);
}
};
int main(int, char *[])
{
std::vector<CustomImageBase*> images;
CustomImage<float>* floatImage = CustomImage<float>::New().GetPointer();
CustomImage<int>* intImage = CustomImage<int>::New().GetPointer();
return EXIT_SUCCESS;
}
エラーが表示されます: itk::Image* から CustomImage* への無効な変換
これはうまくいくことに注意してください:
itk::Image<float>* testFloatImage = itk::Image<float>::New().GetPointer();
CustomImage は itk::Image を継承しているため、問題がわかりませんか?