enum names inside a templated class

Discussion in 'C++' started by Hicham Mouline, Aug 7, 2009.

  1. hi,

    template <int T>
    struct C {
    typedef typename Traits<T>::E1 E1;
    ....
    static void f();
    };

    template<>
    void C<t1>::f()
    {
    // E1 is an enum { x1, x2... } in this case
    // I wanted to use x1 x2 ... without scoping
    // 1. unqualified x1 fails
    // 2. E1::x1 is a non standard extension of msvc
    // C<t1>::x1 is too verbose
    }

    is there a simpler way?

    regards,
     
    Hicham Mouline, Aug 7, 2009
    #1
    1. Advertising

  2. "Hicham Mouline" <> wrote in message
    news:4a7c1613$0$299$...
    > hi,
    >
    > template <int T>
    > struct C {
    > typedef typename Traits<T>::E1 E1;
    > ...
    > static void f();
    > };
    >
    > template<>
    > void C<t1>::f()
    > {
    > // E1 is an enum { x1, x2... } in this case
    > // I wanted to use x1 x2 ... without scoping
    > // 1. unqualified x1 fails
    > // 2. E1::x1 is a non standard extension of msvc
    > // C<t1>::x1 is too verbose
    > }
    >
    > is there a simpler way?
    >
    > regards,


    effectively, I have 12 x enum names. Repeating C<t1>::x1 ... C<t1>::x12
    very tedious

    Can I use the "using" keyword?

    rds,
     
    Hicham Mouline, Aug 7, 2009
    #2
    1. Advertising

  3. Hicham Mouline wrote:
    > "Hicham Mouline" <> wrote in message
    > news:4a7c1613$0$299$...
    >> hi,
    >>
    >> template <int T>
    >> struct C {
    >> typedef typename Traits<T>::E1 E1;
    >> ...
    >> static void f();
    >> };
    >>
    >> template<>
    >> void C<t1>::f()
    >> {
    >> // E1 is an enum { x1, x2... } in this case
    >> // I wanted to use x1 x2 ... without scoping
    >> // 1. unqualified x1 fails
    >> // 2. E1::x1 is a non standard extension of msvc
    >> // C<t1>::x1 is too verbose
    >> }
    >>
    >> is there a simpler way?
    >>
    >> regards,

    >
    > effectively, I have 12 x enum names. Repeating C<t1>::x1 ... C<t1>::x12
    > very tedious
    >
    > Can I use the "using" keyword?


    What's stopping you from trying?

    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, Aug 7, 2009
    #3
  4. Hicham Mouline

    James Kanze Guest

    On Aug 7, 3:09 pm, Victor Bazarov <> wrote:
    > Hicham Mouline wrote:
    > > "Hicham Mouline" <> wrote in message
    > >news:4a7c1613$0$299$...


    > >> template <int T>
    > >> struct C {
    > >> typedef typename Traits<T>::E1 E1;
    > >> ...
    > >> static void f();
    > >> };


    > >> template<>
    > >> void C<t1>::f()
    > >> {
    > >> // E1 is an enum { x1, x2... } in this case
    > >> // I wanted to use x1 x2 ... without scoping
    > >> // 1. unqualified x1 fails
    > >> // 2. E1::x1 is a non standard extension of msvc
    > >> // C<t1>::x1 is too verbose
    > >> }


    > >> is there a simpler way?


    > > effectively, I have 12 x enum names. Repeating C<t1>::x1
    > > ... C<t1>::x12 very tedious


    I'm not sure of the context. With C, C::x12 should be
    sufficient. And IIRC an explicit instantiation is considered
    "inside" C.

    Otherwise... Since you don't seem to mind E1::x1, a typedef for
    C<t1>, or even Traits<t1>, should do the trick.

    > > Can I use the "using" keyword?


    > What's stopping you from trying?


    But he'd still have to have 12 using, one for each enum value.
    The basic problem is that the enum values are dependent names,
    and he needs some simple way of making the compiler realize
    this.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Aug 7, 2009
    #4
    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. RA Scheltema
    Replies:
    3
    Views:
    414
    RA Scheltema
    Jan 6, 2004
  2. Marijn
    Replies:
    5
    Views:
    484
    Marijn
    Feb 13, 2004
  3. Replies:
    0
    Views:
    2,267
  4. Replies:
    1
    Views:
    297
    Kai-Uwe Bux
    Sep 23, 2006
  5. chhenning
    Replies:
    5
    Views:
    378
    chhenning
    Feb 13, 2008
Loading...

Share This Page