template typedef support in g++ ?

P

Paul J. Lucas

Given:

template<typename T,typename U> class C { };
template<typename T> typedef C<T,int> C2;

I get:

test.cpp:2: error: template declaration of 'typedef'

Are template typedefs still not supported in g++ 4.1.2?

- Paul
 
V

Victor Bazarov

Paul said:
Given:

template<typename T,typename U> class C { };
template<typename T> typedef C<T,int> C2;

I get:

test.cpp:2: error: template declaration of 'typedef'

Are template typedefs still not supported in g++ 4.1.2?

There are no template typedefs in C++... As to g++ extensions,
you should ask in 'gnu.g++.*' newsgroup hierarchy.

V
 
A

adrian.hawryluk

Given:

template<typename T,typename U> class C { };
template<typename T> typedef C<T,int> C2;

I get:

test.cpp:2: error: template declaration of 'typedef'

Are template typedefs still not supported in g++ 4.1.2?

- Paul

Maybe what you wanted is this?

template<typename T,typename U> class C { };
typedef C<T,int> C2;


Adrian
 
V

Victor Bazarov

Maybe what you wanted is this?

template<typename T,typename U> class C { };
typedef C<T,int> C2;

'T' seems undefined here. What does your compiler say?

V
 
A

adrian.hawryluk

'T' seems undefined here. What does your compiler say?

V

Oh, I see. I was some how combining Partial Template Specialization
with typedefing a concrete class. Doh!

I wonder what the reasoning is for no templated typedefs. Seems like
a natural extention.


Adrian
 
P

Piyo

Paul said:
Given:

template<typename T,typename U> class C { };
template<typename T> typedef C<T,int> C2;

I get:

test.cpp:2: error: template declaration of 'typedef'

Are template typedefs still not supported in g++ 4.1.2?

- Paul
Hi Paul,

At best, if GNU does support this you will probably need to
download an experimental g++ for this. You can check on their
website to see if this is something they do plan to support.

From a C++ standards perspective, I do not think it has been
ratified. I tried to search the C++ standards website for any
information about this issue but I could not find anything
(but does not mean it isn't being addressed).

Here is a suggested workaround while the different groups
address this issue.

template<typename T,typename U> class C { };
template<typename T>
class C2
{
public:
typedef C<T,int> Type;
};

So now you can do this:

C2<double>::Type foo;

A little awkward looking but should hold you out until
typedef templates is addressed (typedef templates is how
it is referred to by Vandevoorde and Josuttis).

HTH
 

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

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top