I am looking for a way to call the primary class template member function from a member function in a class template specialization. This is similar to the way we can call the base class virtual member function from overriden derived class member function.
// Template defintion
template <typename T>
class MyClass final
{
...
void foo() { ... };
}
// Template specialization for method foo
template<>
void MyClass<MyType>::foo()
{
...
// call primary template's foo() here??
// MyClass::free(); // Warning: All paths through this function will call itself
}
Note: I do not own the code containing the primary template definition, only the template specialization part. I am looking for solutions within these restrictions. There is a similar question How to call a member function of the primary class template from the member function of a specialization without these restrictions, and I cannot use the answers there.
You can simply call your primary none specialized template by using a new type, which you don't have specialized before.
Something like:
Quite clear that this will not help if you need your primary class to have the same data type as your specialization because it access some data in it.