Search code examples
c++itk

C++ abstract type declaration


I am using ITK. itk::LinearInterpolateImageFunction is a subclass of itk::InterpolateImageFunction.

Why is the statment below not valid?

itk::InterpolateImageFunction<ImageType,double>::Pointer interpolator = itk::LinearInterpolateImageFunction<ImageType, double>::New();

The error I get is

error: conversion from itk::LinearInterpolateImageFunction<itk::Image<unsigned char, 3u>, double>::Pointer {aka itk::SmartPointer<itk::LinearInterpolateImageFunction<itk::Image<unsigned char, 3u>, double> >} to non-scalar type itk::InterpolateImageFunction<itk::Image<unsigned char, 3u>, double>::Pointer {aka itk::SmartPointer<itk::InterpolateImageFunction<itk::Image<unsigned char, 3u>, double> >} requested


Solution

  • The InterpolateImageFunction::Pointer typedef is to SmartPointer<InterpolateImageFunction>. Unlike std::shared_ptr, itk::SmartPointer does not support conversions between smart pointers of related types. That is, InterpolateImageFunction<X,Y>::Pointer and LinearInterpolateImageFunction<X,Y>::Pointer are unrelated types.