@JLBorges, Thanks!
That looks like a neat way to do specialization.
I have one question, however. I am very new to templates, so please excuse my understanding.
Your method does specialization at the 'template class' level based on the signature of the parameters. Isn't it more of a overloading than specialization? Please correct me if I am wrong.
What I thought was when I typedef an 'instantiation' of a template class, that class is an actual full-fledged class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
// I have a template class
template<class T, T invalidVal, int e> class A
{
static inline bool dummy(T value)
{
return 0;
}
}
// Now I create classes from the above template class with T=void*, invalidVal=NULL & e=0
// And with T=void *, invalidVal=NULL & e=1
// And I typedef these classes to use them later
typedef A<void *, (void *)NULL, 0> A_0;
typedef A<void *, (void *)NULL, 1> A_1;
// So now, what I was expecting was that A_0 & A_1 are classes and they can have their own
// specialized dummy() method
// So I tried following -
inline bool A_0::dummy(void *value)
{
return value != invalidVal;
}
inline bool A_1::dummy(void *value)
{
return value == invalidVal;
}
|
But this specialization does not work as expected - using g++-4.7 - on Linux.
The above code works as is in a Windows environment.
For linux, as I had mentioned in my first post, I get following 2 errors -
1)specializing member ‘A<void*, 0u, 0>::dummy’ requires ‘template<>’ syntax &
2) invalidVal was not declared in this scope
Sorry for repeating the question.
But I am wondering if such specialization can be done or not and if so, then what am I missing that g++ is expecting?
Thanks!