Ioannis said:
So if you define a static function (for some type), you have to use that
type to call it.
While this statement is 100% true for non-template types, I feel it
requires clarification when applied to classes that are created by the
compiler as a result of a template instantiation.
Consider the following valid code sample:
#include <iostream>
template <class T = int>
class Foo {
public:
static void bar() {
std::cout << "I am Foo::bar()...\n";
}
};
int main() {
Foo<>::bar();
return 0;
}
The first point I would like to make is that I never actually defined
the function Foo<int>::bar(), rather the compiler defined it for me.
Therefore, one doesn't really define static functions when writing a
template class, merely, one defines the template so that the compiler
can generate static functions for us.
Furthermore, if your template class has default parameters, it is not
required of you to explicitly provide them in order to make a call to a
static function. As you can see in the example above, a call to
Foo<int>::bar() was made as Foo<>::bar().
Thus, while one must at least implicitly use a type to make a call to a
static function that is created as a result of a template
instantiation, explicit use of a type is not required, only the braces
<>.
Regards,
Michael Loritsch