Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > using typename

Reply
Thread Tools

using typename

 
 
mlt
Guest
Posts: n/a
 
      06-29-2009
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:ointer fixed,
MovingImageReaderType:ointer 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:ointer fixed,
typename MovingImageReaderType:ointer 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?


 
Reply With Quote
 
 
 
 
Maxim Yegorushkin
Guest
Posts: n/a
 
      06-29-2009
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:ointer fixed,
> MovingImageReaderType:ointer 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:ointer fixed,
> typename MovingImageReaderType:ointer 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/techt...ates/#typename

--
Max
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
class vs. typename Alexander Malkis C++ 7 10-20-2012 09:03 PM
Q: typename or not typename? Jakob Bieling C++ 2 03-14-2006 03:44 PM
implicit typename in template Steve Hill C++ 1 09-06-2003 07:52 AM
typename, typedef, and resolution Gina Yarmel C++ 4 08-13-2003 04:06 PM
Gcc complain about typename Xavier Decoret C++ 1 07-04-2003 05:27 AM



Advertisments