By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,706 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

template problem with MIPSpro compiler

P: n/a
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".
Jul 22 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.