Discussion:
template typedef support in g++ ?
(too old to reply)
Paul J. Lucas
2007-03-06 19:01:54 UTC
Permalink
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
Victor Bazarov
2007-03-06 20:15:20 UTC
Permalink
Post by Paul J. Lucas
template<typename T,typename U> class C { };
template<typename T> typedef C<T,int> C2;
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
a***@gmail.com
2007-03-06 20:59:27 UTC
Permalink
Post by Paul J. Lucas
template<typename T,typename U> class C { };
template<typename T> typedef C<T,int> C2;
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
Victor Bazarov
2007-03-06 21:44:19 UTC
Permalink
Post by a***@gmail.com
Post by Paul J. Lucas
template<typename T,typename U> class C { };
template<typename T> typedef C<T,int> C2;
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;
'T' seems undefined here. What does your compiler say?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
a***@gmail.com
2007-03-06 23:44:04 UTC
Permalink
Post by Victor Bazarov
Post by a***@gmail.com
Post by Paul J. Lucas
template<typename T,typename U> class C { };
template<typename T> typedef C<T,int> C2;
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;
'T' seems undefined here. What does your compiler say?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
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
Piyo
2007-03-07 05:47:42 UTC
Permalink
Post by Paul J. Lucas
template<typename T,typename U> class C { };
template<typename T> typedef C<T,int> C2;
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

Loading...