B
braton
Hello
I need some help with template functions specialization. Consider the
following code:
#include <iostream>
template<class T, int I>
class C {
public:
int Member(void);
};
template<class T, int I>
int C<T,I>::Member(void) {
T t();
return I;
}
int main(void) {
C<int,3> c;
std::cout << c.Member() << std::endl;
return 0;
}
So far, everything works fine. When I provide explicit specialization,
everything is OK too:
template<>
int C<int,5>::Member(void) {
return 555;
}
The problem appears, when I try to partially specialize that function:
template<class U>
int C<U,3>::Member(void) {
U u();
return 6;
}
I got some errors under Visual C++ Express:
-) error C3860: template argument list following class template name
must list parameters in the order used in template parameter list
-) error C2995: 'int C<T,I>::Member(void)' : function template has
already been defined
-) error C2264: 'C<T,I>::Member' : error in function definition or
declaration; function not called
and under Comeau online compiler:
-) "ComeauTest.c", line 21: error: template argument list must match
the parameter list
int C<U,3>::Member(void) {
Is this possible to do in standard C++ way? Thanks for your help.
braton
I need some help with template functions specialization. Consider the
following code:
#include <iostream>
template<class T, int I>
class C {
public:
int Member(void);
};
template<class T, int I>
int C<T,I>::Member(void) {
T t();
return I;
}
int main(void) {
C<int,3> c;
std::cout << c.Member() << std::endl;
return 0;
}
So far, everything works fine. When I provide explicit specialization,
everything is OK too:
template<>
int C<int,5>::Member(void) {
return 555;
}
The problem appears, when I try to partially specialize that function:
template<class U>
int C<U,3>::Member(void) {
U u();
return 6;
}
I got some errors under Visual C++ Express:
-) error C3860: template argument list following class template name
must list parameters in the order used in template parameter list
-) error C2995: 'int C<T,I>::Member(void)' : function template has
already been defined
-) error C2264: 'C<T,I>::Member' : error in function definition or
declaration; function not called
and under Comeau online compiler:
-) "ComeauTest.c", line 21: error: template argument list must match
the parameter list
int C<U,3>::Member(void) {
Is this possible to do in standard C++ way? Thanks for your help.
braton