using typename

M

mlt

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?
 
M

Maxim Yegorushkin

mlt said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top