A simple workaround is to write a wrapper function which just calls the template. For example:
private:
template<typename ENABLER>
Object& get_()
{
return this->object_;
}
template<typename Object2>
Object& get_()
{
return get_<typename std::enable_if<!std::is_same<Object2,NullObject>::value>::type>();
}
public:
//Overload for default Object template parameter:
Object& get()
{
return get_<Object>();
}
Of course the compiler is cappable of inline all the wrappings, so performance is not a concern here.
Note that I have dopped the const
qualifier: You are returning a reference to internal data, that getters cannot/shouldn't be const
.