template typedef support in g++ ?

Discussion in 'C++' started by Paul J. Lucas, Mar 6, 2007.

  1. 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
     
    Paul J. Lucas, Mar 6, 2007
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Mar 6, 2007
    #2
    1. Advertising

  3. Paul J. Lucas

    Guest

    On Mar 6, 3:01 pm, (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
     
    , Mar 6, 2007
    #3
  4. wrote:
    > On Mar 6, 3:01 pm, (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
     
    Victor Bazarov, Mar 6, 2007
    #4
  5. Paul J. Lucas

    Guest

    On Mar 6, 5:44 pm, "Victor Bazarov" <> wrote:
    > wrote:
    > > On Mar 6, 3:01 pm, (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
     
    , Mar 6, 2007
    #5
  6. Paul J. Lucas

    Piyo Guest

    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
     
    Piyo, Mar 7, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert A. T. Kaldy

    template typedef as return type

    Robert A. T. Kaldy, Jul 9, 2003, in forum: C++
    Replies:
    1
    Views:
    428
    Michael Kochetkov
    Jul 9, 2003
  2. Richard van Wegen

    Typedef of a template?

    Richard van Wegen, Jul 14, 2003, in forum: C++
    Replies:
    3
    Views:
    459
    Richard van Wegen
    Jul 15, 2003
  3. Adam Nielsen
    Replies:
    3
    Views:
    422
  4. oor
    Replies:
    0
    Views:
    1,396
  5. Replies:
    1
    Views:
    623
Loading...

Share This Page