Template typedef.

Discussion in 'C++' started by JC, Jun 16, 2009.

  1. JC

    JC Guest

    I have two template classes:

    template <typename X> class Simple { ... };

    template <typename T, typename S> class Complex { ... };

    The "Complex" class typically takes some Simple type as it's S
    parameter, e.g.:

    Complex<int, Simple<int> >

    I'm trying to make typedefs for some of the more common cases. For
    cases where the types are already known, it's easy (note that S is not
    always a Simple<>, it can be anything,):

    typedef Complex<int, Simple<int> > ComplexInt;
    typedef Complex<Something, Another> ComplexSomething;

    Is there a way to make something like a typedef for cases where T and
    X are unknown but are the same type, and S is a Simple<T>, and still
    have T be a template parameter? E.g. something like (I know this is
    incorrect):

    template <typename T> Complex<T, Simple<T> > ComplexGeneric;

    So that later on all you need to do is this:

    ComplexGeneric<int> g;

    And it is equivalent to:

    Complex<int, Simple<int> > g;

    Thanks,
    Jason
    JC, Jun 16, 2009
    #1
    1. Advertising

  2. JC wrote:
    > [..]
    > I'm trying to make typedefs for some of the more common cases. [..]


    Search the archives (using http://groups.google.com) for "template
    typedefs", and you shall find.

    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, Jun 16, 2009
    #2
    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:
    416
    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:
    445
    Richard van Wegen
    Jul 15, 2003
  3. Adam Nielsen
    Replies:
    3
    Views:
    407
  4. oor
    Replies:
    0
    Views:
    1,346
  5. Replies:
    1
    Views:
    604
Loading...

Share This Page