[Insight-users] strange Template - Errors in MSVC 7.1

Luis Ibanez luis.ibanez at kitware.com
Mon Feb 20 12:52:41 EST 2006



Hi Henning,


1) The reason why you cannot create an Image<> of pixel type Transform,
    is that the constructors of Transform are protected. This is done on
    purpose because Transform are intended to be managed through Smart
    Pointers and to be constructed only via the New() operator.

    What you could do instead is to create an image whose pixel type is
    TransformType::Pointer. Note that will will just give you the place
    holder for the transform pointers. You are still responsible for
    constructing the transform via the New() method, and also for
    initialize them using their respective Set() methods.


    Your declaration could be something like:


      typedef typename myTransform::Pointer  myTransformPointer;
      typedef typename Image< myTransformPointer,
                            myImageDimension > TransformImageType;



2) The difference between "typedef" and "typedef typename"
    is that "typedef typename" is required in the case where
    the following three conditions are satisfied:

      a) you are making a typedef inside a templated class
      b) the typedef uses a trait from a class
      c) the class from which the trait is taken is related
         or depends on the template parameter of the current
         class.

    For most details on the use of "typename" you should refer
    to a recent introductory book on C++.





3) The difference between declaring templates with


              template< class T >

   and

              template< typename T >




    is that the second form is the "formally correct"
    one,


         but... some compilers do not accept it.


    So, "typename T" is the theoretically correct thing to do,
    while "class T" is the de-facto right thing to do.



       Regards,



          Luis




=====================
Henning Meyer wrote:
> Hello,
> 
> I try to implement a new ImageRegistrationMethod, but I can't really
> get to work because of strange errors from the MS VC compiler 7.1.
> For example I wrote this small piece of code:
> 
> template <typename TImage >
> class ITK_EXPORT myTest : public ProcessObject {
> 	public:
>   static const unsigned int myImageDimension = itk::GetImageDimension<
> TImage >::ImageDimension;
>   typedef ImageToImageMetric< TImage, TImage > myMetric;
>   typedef typename myMetric::TransformType myTransform;
>   typedef typename Image< myTransform, myImageDimension > TransformImageType;
>   typedef typename TransformImageType::Pointer     TransformImagePointer;
> };
> 
> When I instatiate this Class by:
> itk::myTest< itk::Image< float, 2> > tut;
> 
> I get a long list of errors pointing to ~ImportImageContainer().
> Why this?
> What's wrong with my code?
> How should I create an image of transformations?
> 
> And finally: Whats the difference between typdef and typedef typename?
> Whats the difference between template <class T> and template <typename
> T>?
> 
> Thank you!
> 
> Henning
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 
> 



More information about the Insight-users mailing list