I know from this thread - template class member function only specialization that if I specialize a class template, I need to specialize all the member functions.
So, my rationale was that I would 'instantiate' a template class. (Not sure if its the right way of saying it)
Then, since this instantiated class is a full-fledged class, I can specialize a particular method.
// I have a template class like this -
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;
}
The above code worked in a Windows environment. (Visual Studio 2008)
But this specialization does not work - using g++-4.7 - on Linux. By reading through some other threads, I am also passing -std=c++11 to my g++ compilation command.
I get following 2 errors -
1. specializing member ‘A<void*, 0u, 0>::dummy’ requires ‘template<>’ syntax
2. invalidVal was not declared in this scope
Now, error no. 1 goes away if I add a template<>
before inline bool A_0::dummy(void *value)
which makes me more worried, since I know the specialization did not happen as I wanted.
The error no. 2 doesn't go away.
I am getting more and more confused about template class member function specialization. What am I missing out here? Any reasons that g++ is complaining? Any ideas?
Thanks!