Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > template typedef support in g++ ?

Reply
Thread Tools

template typedef support in g++ ?

 
 
Paul J. Lucas
Guest
Posts: n/a
 
      03-06-2007
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
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      03-06-2007
Paul J. Lucas wrote:
> 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
adrian.hawryluk@gmail.com
Guest
Posts: n/a
 
      03-06-2007
On Mar 6, 3:01 pm, pauljlucas.removet...@removethistoo.mac.com (Paul
J. Lucas) wrote:
> 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

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      03-06-2007
wrote:
> On Mar 6, 3:01 pm, pauljlucas.removet...@removethistoo.mac.com (Paul
> J. Lucas) wrote:
>> 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;


'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


 
Reply With Quote
 
adrian.hawryluk@gmail.com
Guest
Posts: n/a
 
      03-06-2007
On Mar 6, 5:44 pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
> adrian.hawry...@gmail.com wrote:
> > On Mar 6, 3:01 pm, pauljlucas.removet...@removethistoo.mac.com (Paul
> > J. Lucas) wrote:
> >> 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;

>
> '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

 
Reply With Quote
 
Piyo
Guest
Posts: n/a
 
      03-07-2007
Paul J. Lucas wrote:
> 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
 
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
typedef of template<T> x to member x in template class squarewave@blockhead.net C++ 1 02-20-2009 08:15 PM
CRTP-problem: How can the base class typedef a derived class' typedef? oor C++ 0 05-20-2008 12:39 PM
Extracting template types from a typedef'd template declaration Adam Nielsen C++ 3 10-19-2007 09:54 AM
Typedef of a template? Richard van Wegen C++ 3 07-15-2003 07:22 AM
template typedef as return type Robert A. T. Kaldy C++ 1 07-09-2003 06:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57