在以下代码中:
#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,我不明白这个问题?