L
Levent
Hi,
Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1):
#include <iostream>
template<class T, unsigned N>
struct Foo {
void func();
};
template<class T, unsigned N>
void Foo<T,N>::func() {
std::cout << "Primary -- "
<< "T is " << typeid(T).name() << " -- "
<< "N=" << N
<< std::endl;
}
template<class T>
void Foo<T,3>::func() {
std::cout << "Specialized for N=3 -- "
<< "T is " << typeid(T).name() << " -- "
<< std::endl;
}
int main() {
Foo<double,3> d;
Foo<int,5> i;
d.func();
i.func();
return 0;
}
gcc compiler error: no `void Foo<T, 3>::func()' member function declared in
class `Foo<T, 3>'
(VC7.1 error is similar)
On the other hand, full specialization of the member works (without
specializing the whole class). (try replacing `template<class T> void
Foo<T,3>::func()' with `template<> void Foo<double,3>::func()')
If this behaviour is how it is defined in the standard, what may be a
possible workaround to achieve partial specialization on member functions?
thank you
- sly.
Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1):
#include <iostream>
template<class T, unsigned N>
struct Foo {
void func();
};
template<class T, unsigned N>
void Foo<T,N>::func() {
std::cout << "Primary -- "
<< "T is " << typeid(T).name() << " -- "
<< "N=" << N
<< std::endl;
}
template<class T>
void Foo<T,3>::func() {
std::cout << "Specialized for N=3 -- "
<< "T is " << typeid(T).name() << " -- "
<< std::endl;
}
int main() {
Foo<double,3> d;
Foo<int,5> i;
d.func();
i.func();
return 0;
}
gcc compiler error: no `void Foo<T, 3>::func()' member function declared in
class `Foo<T, 3>'
(VC7.1 error is similar)
On the other hand, full specialization of the member works (without
specializing the whole class). (try replacing `template<class T> void
Foo<T,3>::func()' with `template<> void Foo<double,3>::func()')
If this behaviour is how it is defined in the standard, what may be a
possible workaround to achieve partial specialization on member functions?
thank you
- sly.