Only possible to access typedef'ed template parameters?

N

none

In a class I do:

#include "MyImageImages.h"
#include ""

class Test{

public:
....
....

typedef typename MyImageTypes::Image<PixelType, Dimension> ImageType;
typedef MyClass<ImageType> MyClassType;



// This gives an error:
typedef typename MyClassType::ImageType ImageType2;

};




Where:


template< typename ImageType >
class MyClass {

public:



};



I get an error when I try to access the template parameter in MyClass. I
have tried to typedef the template parameter and rename it like:

typedef ImageType Bob;

and then I can do (ion class Test):

typedef typename MyClassType::Bob ImageType2;


Is it only possible to access template parameters that have been typedef'ed?
 
M

Michael Doubez

In a class I do:

#include "MyImageImages.h"
#include ""

class Test{

public:
...
...

typedef typename MyImageTypes::Image<PixelType, Dimension>  ImageType;
typedef MyClass<ImageType>                                  MyClassType;

// This gives an error:
typedef typename MyClassType::ImageType ImageType2;

};

You are using typename in a non-template class.
This is either an error (from the current standard) or the code you
are showing is incomplete.

Where:

template< typename ImageType >
class MyClass {

public:

};
I get an error when I try to access the template parameter in MyClass.

You cannot access a template parameter.
I
have tried to typedef the template parameter and rename it like:

                typedef ImageType Bob;

and then I can do (ion class Test):

                typedef typename MyClassType::Bob ImageType2;

Is it only possible to access template parameters that have been typedef'ed?

Yes and no, you can recover it:

template<class T>
struct Parameter;

template< template<class> class TTemplate, class TParam1 >
struct Parameter< TTemplate<TParam1> >
{
typedef TParam1 param1_type;
};
// other cases of first parameter

And you can use:

typedef Parameter<MyClassType>::param1_type ImageType;

Personally, I usually define a typedef for each of the parameters and
use them:

template< typename TImageType >
class MyClass {
public:
typedef TImageType ImageType;
};
 

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,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top