template function in inner class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christof Warlich

    template function in inner class

    Hi,

    could anyone tell what's wrong with this?:

    template<int x>
    struct Outer {
    struct Inner {
    template<int yvoid finner() {}
    };
    Inner inner;
    void fouter() {inner.finner<0 >();}
    };

    Thanks,

    Christof
  • Lionel B

    #2
    Re: template function in inner class

    On Tue, 07 Oct 2008 10:41:59 +0200, Christof Warlich wrote:
    Hi,
    >
    could anyone tell what's wrong with this?:
    >
    template<int x>
    struct Outer {
    struct Inner {
    template<int yvoid finner() {}
    };
    Inner inner;
    void fouter() {inner.finner<0 >();}
    void fouter() {inner.template finner<0>();}
    };
    compiles for me. I'm not clear on why this might be required.

    --
    Lionel B

    Comment

    • Christof Warlich

      #3
      Re: template function in inner class

      Lionel B schrieb:
      compiles for me. I'm not clear on why this might be required.
      It doesn't compile with my gcc:

      $ g++ --version
      g++ (GCC) 3.4.6
      Copyright (C) 2006 Free Software Foundation, Inc.
      This is free software; see the source for copying conditions. There is NO
      warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      $ g++ -c tst.cc
      tst.cc: In member function `void Outer<x>::foute r()':
      tst.cc:8: error: expected primary-expression before ')' token

      So this may be a compiler bug?! I'll try with a more recent gcc version
      tonight. Which compiler did you use?

      Thanks and regards,

      Christof


      Comment

      • Lionel B

        #4
        Re: template function in inner class

        On Tue, 07 Oct 2008 12:38:43 +0200, Christof Warlich wrote:
        Lionel B schrieb:
        >compiles for me. I'm not clear on why this might be required.
        >
        It doesn't compile with my gcc:
        >
        $ g++ --version
        g++ (GCC) 3.4.6
        Copyright (C) 2006 Free Software Foundation, Inc. This is free software;
        see the source for copying conditions. There is NO warranty; not even
        for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ g++ -c tst.cc
        tst.cc: In member function `void Outer<x>::foute r()': tst.cc:8: error:
        expected primary-expression before ')' token
        >
        So this may be a compiler bug?! I'll try with a more recent gcc version
        tonight. Which compiler did you use?
        Odd. The amended code compiles for me here with gcc 3.4.6 (also gcc
        4.3.1, 4.3.0 4.1.2 and Intel icc 10.0).

        All the above gcc versions reject your original code, although icc
        accepts it.

        Comeau (about as standards-compliant as it gets) rejects your original
        code with:

        "ComeauTest .c", line 7: error: expected an expression
        void fouter() {inner.finner<0 >();}

        and accepts the amended version.

        --
        Lionel B

        Comment

        • Triple-DES

          #5
          Re: template function in inner class

          On 7 Okt, 12:38, Christof Warlich <cwarl...@alcat el-lucent.dewrote:
          Lionel B schrieb:
          >
          compiles for me. I'm not clear on why this might be required.
          >
          It doesn't compile with my gcc:
          >
          $ g++ --version
          g++ (GCC) 3.4.6
          Copyright (C) 2006 Free Software Foundation, Inc.
          This is free software; see the source for copying conditions.  There isNO
          warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
          $ g++ -c tst.cc
          tst.cc: In member function `void Outer<x>::foute r()':
          tst.cc:8: error: expected primary-expression before ')' token
          >
          So this may be a compiler bug?! I'll try with a more recent gcc version
          tonight. Which compiler did you use?
          >
          Thanks and regards,
          >
          Christof
          Did you try:

          template<int x>
          struct Outer {
          struct Inner {
          template<int yvoid finner() {}
          };
          Inner inner;
          void fouter() {inner.template finner<0>();}
          };

          ?





          Comment

          • Christof Warlich

            #6
            Re: template function in inner class

            Triple-DES schrieb:
            Did you try:
            >
            template<int x>
            struct Outer {
            struct Inner {
            template<int yvoid finner() {}
            };
            Inner inner;
            void fouter() {inner.template finner<0>();}
            };
            No, I missed Lionel's change. With the change, it works
            for me as well :-).

            Comment

            Working...