Calling general template function from specialization
-
How do I explicitly call the non-specialized sibling of a template function from within the specialized function?
I have
@template <class valueT>
class CFuzzy
{
// Other methods...static bool isGreaterOrEqual(valueT value1, valueT value2);
};
template <>
class CFuzzy<double>
{
// Other methods...static bool isGreaterOrEqual(double value1, double value2);
};
@CFuzzy has several methods that need to be specialized. However, isGreateOrEqual would not need to be specialized.
Since I have to do it anyway, I am looking for a way to call my general template sibling, so as not to duplicate the code.Something like
@bool CFuzzy<double>::isGreaterOrEqual(double value1,
double value2)
{
CFuzzy<valueT>::isGreaterOrEqual(value1, value2); // This doesn't work
}@Is this possible? If so, which syntax do I use?
-
There you should have CFuzzy<double>::... but that will recursively call the same function.
Anyway i think you can't call that function from specialization, but an alternative is to specialize the functions not the class:
@
template <class valueT>
class CFuzzy
{
public:
// Other methods...
static bool OtherMethod(valueT value);static bool isGreaterOrEqual(valueT value1, valueT value2);
};
//isGreaterOrEqual - never specialized
template <class valueT>
bool CFuzzy<valueT>::isGreaterOrEqual(valueT value1,
valueT value2)
{
return value1 >= value2; //my dummy implementation
}//OtherMethod - valueT template
template <class valueT>
bool CFuzzy<valueT>::OtherMethod(valueT value)
{
return value > 0; //my dummy implementation
}//OtherMethod - template specialization for double
template<>
bool CFuzzy<double>::OtherMethod(double value)
{
return value > -1; //my dummy implementation
}
@ -
Thank you. I did even start out with functions, but found that putting functions that belong together into a class to be neater.
I think, in this case, I'll go with the code duplication, properly test it and never change it again (or so I hope).