using typename

Discussion in 'C++' started by mlt, Jun 29, 2009.

  1. mlt

    mlt Guest

    In a class MyReg I have the below constructor:

    //template<typename T>
    class MyReg{
    public:
    ...
    typedef itk::Image< PixelType, Dimension > FixedImageType;
    typedef itk::Image< PixelType, Dimension > MovingImageType;
    typedef itk::ImageFileReader< FixedImageType > FixedImageReaderType;
    typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;

    MyReg(MyParameters param, FixedImageReaderType::pointer fixed,
    MovingImageReaderType::pointer moving){
    this->param = param;
    this->fixedImageReader = fixed;
    this->movingImageReader = moving;
    }

    };

    This compiles fine. But if I use the template declaration:

    template<typename T>
    class MyReg{
    public:
    ....
    ....

    I get the compiler error:

    Error 2 error C2061: syntax error : identifier 'Pointer'

    I have found that a fix is to add typename to the arguments in the
    constructor:


    MyReg(MyParameters param, typename FixedImageReaderType::pointer fixed,
    typename MovingImageReaderType::pointer moving){


    But why does this solve the problem? I have read that when typename is used
    its to tell the compiler that follwing code is a type, but would that not be
    obvious in a constructor?
     
    mlt, Jun 29, 2009
    #1
    1. Advertising

  2. mlt wrote:
    > In a class MyReg I have the below constructor:
    >
    > //template<typename T>
    > class MyReg{
    > public:
    > ...
    > typedef itk::Image< PixelType, Dimension > FixedImageType;
    > typedef itk::Image< PixelType, Dimension > MovingImageType;
    > typedef itk::ImageFileReader< FixedImageType > FixedImageReaderType;
    > typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;
    >
    > MyReg(MyParameters param, FixedImageReaderType::pointer fixed,
    > MovingImageReaderType::pointer moving){
    > this->param = param;
    > this->fixedImageReader = fixed;
    > this->movingImageReader = moving;
    > }
    >
    > };
    >
    > This compiles fine. But if I use the template declaration:
    >
    > template<typename T>
    > class MyReg{
    > public:
    > ...
    > ...
    >
    > I get the compiler error:
    >
    > Error 2 error C2061: syntax error : identifier 'Pointer'
    >
    > I have found that a fix is to add typename to the arguments in the
    > constructor:
    >
    >
    > MyReg(MyParameters param, typename FixedImageReaderType::pointer fixed,
    > typename MovingImageReaderType::pointer moving){
    >
    > But why does this solve the problem? I have read that when typename is used
    > its to tell the compiler that follwing code is a type, but would that not be
    > obvious in a constructor?


    http://www.comeaucomputing.com/techtalk/templates/#typename

    --
    Max
     
    Maxim Yegorushkin, Jun 29, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xavier Decoret

    Gcc complain about typename

    Xavier Decoret, Jul 4, 2003, in forum: C++
    Replies:
    1
    Views:
    498
    Dhruv
    Jul 4, 2003
  2. Gina Yarmel

    typename, typedef, and resolution

    Gina Yarmel, Aug 13, 2003, in forum: C++
    Replies:
    4
    Views:
    4,763
    Sergei Emantayev
    Aug 13, 2003
  3. Steve Hill

    implicit typename in template

    Steve Hill, Sep 6, 2003, in forum: C++
    Replies:
    1
    Views:
    445
    ES Kim
    Sep 6, 2003
  4. Alexander Malkis

    class vs. typename

    Alexander Malkis, Apr 6, 2004, in forum: C++
    Replies:
    7
    Views:
    13,097
    psubramani
    Oct 20, 2012
  5. Jakob Bieling

    Q: typename or not typename?

    Jakob Bieling, Mar 14, 2006, in forum: C++
    Replies:
    2
    Views:
    356
    Rolf Magnus
    Mar 14, 2006
Loading...

Share This Page