Is it possible (without using macros) to have a template parameter deduced by a compiler in a static function that takes no parameters?
struct Widget
{
template<typename T = ?>
static void foo()
{
}
};
struct Base : Widget {};
struct Derived : Base {};
Base::foo(); // T should be deduced as Base
Derived::foo(); // T should be deduced as Derived
In my use case, writing Base::foo<Base>();
would not only be redundant (the compiler already has that information, as I've already said Base::
) but would also introduce a possibility to make a mistake - calling Base::foo<SomeOtherType>();
should be disallowed.
Is there any way to distinguish, at a compile time, whether foo is called as Base::foo()
or as Derived::foo()
?