typedef with a template

Discussion in 'C++' started by Xavier Serrand, Jul 10, 2007.

  1. Hello all,

    can i typedef such a déclaration ??

    template <class T, int i>
    struct MyStruc
    {
    /* some members here ...*/
    };

    Thanks in advance

    Xavier
     
    Xavier Serrand, Jul 10, 2007
    #1
    1. Advertising

  2. Xavier Serrand wrote:
    > can i typedef such a déclaration ??
    >
    > template <class T, int i>
    > struct MyStruc
    > {
    > /* some members here ...*/
    > };


    typedef MyStruct<int,42> MyInt42Struct;

    Beyond that, ask more particular questions.

    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, Jul 10, 2007
    #2
    1. Advertising

  3. "Xavier Serrand" <> a écrit dans le message de
    news:4693ce6b$0$5069$...
    > Hello all,
    >
    > can i typedef such a déclaration ??
    >
    > template <class T, int i>
    > struct MyStruc
    > {
    > /* some members here ...*/
    > };
    >
    > Thanks in advance
    >
    > Xavier
    >
    >


    Ok this seems to work

    template <class T, int i>
    typedef struct MyStruc
    {
    /* some members here ...*/
    } MyStructure;

    Xavier
     
    Xavier Serrand, Jul 10, 2007
    #3
  4. Xavier Serrand

    spekyuman Guest

    On Jul 10, 2:21 pm, "Xavier Serrand" <> wrote:
    > Hello all,
    >
    > can i typedef such a déclaration ??
    >
    > template <class T, int i>
    > struct MyStruc
    > {
    > /* some members here ...*/
    >
    > };
    >
    > Thanks in advance
    >
    > Xavier


    You are restricted to giving the template type definition a specific
    "for-instance:"

    typedef MyStruc<int, 0> intPoop;
    typedef MyStruc<char, 1> charPoop;
    typedef MyStruc<float, 2> floatPoop;

    intPoop<chicken, 123456789> henType; // Invalid
    intPoop valid0; // Do these need comments? Yes, always!
    charPoop valid1;
    floatPoop valid2;
     
    spekyuman, Jul 10, 2007
    #4
  5. "Xavier Serrand" <> a écrit dans le message de
    news:4693d24a$0$5106$...
    >
    > "Xavier Serrand" <> a écrit dans le message de
    > news:4693ce6b$0$5069$...
    > > Hello all,
    > >
    > > can i typedef such a déclaration ??
    > >
    > > template <class T, int i>
    > > struct MyStruc
    > > {
    > > /* some members here ...*/
    > > };
    > >
    > > Thanks in advance
    > >
    > > Xavier
    > >
    > >

    >
    > Ok this seems NOT to work
    >
    > template <class T, int i>
    > typedef struct MyStruc
    > {
    > /* some members here ...*/
    > } MyStructure;
    >
    > Xavier
    >
    >
     
    Xavier Serrand, Jul 10, 2007
    #5
  6. "spekyuman" <> a écrit dans le message de
    news:...
    On Jul 10, 2:21 pm, "Xavier Serrand" <> wrote:
    > Hello all,
    >
    > can i typedef such a déclaration ??
    >
    > template <class T, int i>
    > struct MyStruc
    > {
    > /* some members here ...*/
    >
    > };
    >
    > Thanks in advance
    >
    > Xavier


    You are restricted to giving the template type definition a specific
    "for-instance:"

    typedef MyStruc<int, 0> intPoop;
    typedef MyStruc<char, 1> charPoop;
    typedef MyStruc<float, 2> floatPoop;

    intPoop<chicken, 123456789> henType; // Invalid
    intPoop valid0; // Do these need comments? Yes, always!
    charPoop valid1;
    floatPoop valid2;


    Thanks, Speykuman

    I found a way to typedef my templated type as i wanted
    Because T is defined in the class declaration, we can do :

    template <typename T> class CTemplated
    {
    typedef struct MyStruc<T> MyStructureT;
    MyStructureT m_one;
    CTemplated(int n) {m_one.x = n;}
    };


    Xavier
     
    Xavier Serrand, Jul 10, 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