template problem with MIPSpro compiler

R

r5

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".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top