template problem with MIPSpro compiler

Discussion in 'C++' started by r5, May 28, 2004.

  1. r5

    r5 Guest

    I'm using the MIPSpro Compiler and having trouble defining
    a function template (involving array size specifiers as
    template arguments) inside a class. The same definition
    compiles fine outside the class. I have listed a short
    sample code and resulting error messages at the end of
    this posting.

    Is there a known work-around that fixes this "inside
    the class" problem for SGI compilers -- short of
    upgrading beyond v7.2.1?

    One final note, the code below compiles and runs
    correctly with g++. Thanks.


    //////////////// junk.C ////////////////
    #include <iostream.h>

    template <typename T, size_t N>
    size_t count1(T (&array)[N] )
    {
    return N;
    }

    class A {
    public:
    template <typename T, size_t N> size_t count2(T (&array)[N]);

    };

    template <typename T, size_t N> size_t A::count2(T (&array)[N])
    {
    return N;
    }


    int main()
    {
    A a;
    int b[3];

    cerr << count1(b) << " " << a.count2(b) << endl;

    return 0;
    }
    ////////////////////////////////

    % CC -version
    MIPSpro Compilers: Version 7.2.1

    % CC -n32 junk.C
    "junk.C", line 12: error(1424): constant "N" is not used in declaring the
    parameter types of function template "A::count2"
    template <typename T, size_t N> size_t count2(T (&array)[ N ] );
    ^

    "junk.C", line 16: error(1424): constant "N" is not used in declaring the
    parameter types of function template "A::count2"
    template <typename T, size_t N> size_t A::count2(T (&array)[N] )
    ^

    "junk.C", line 27: error(1278): no instance of function template "A::count2"
    matches the argument list
    argument types are: (int [3])
    cerr << count1(b) << " " << a.count2(b) << endl;
    ^

    3 errors detected in the compilation of "junk.C".
     
    r5, May 28, 2004
    #1
    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. Evan David Light
    Replies:
    6
    Views:
    484
    David Anderson
    Dec 1, 2003
  2. Christopher M. Lusardi
    Replies:
    4
    Views:
    459
    Thomas Matthews
    May 13, 2004
  3. Shlomi
    Replies:
    5
    Views:
    333
    Shlomi
    May 20, 2004
  4. Bram Stolk
    Replies:
    4
    Views:
    362
    Bram Stolk
    May 25, 2005
  5. mdh
    Replies:
    17
    Views:
    551
    James Kuyper
    Nov 30, 2007
Loading...

Share This Page