Why is the default template template for mem fun explicitly defined as illegal?

In N3126 ( Warning: very large PDF ) 14.1 / 9, there are two statements that make me confused:

#1: "The default template argument may be specified in the template declaration."

#2: "The default argument template should not be specified in the parameter list of the template definition for the member of the class template that appears outside the class of participants."

#1 means the following code is legal:

 template <class T = int> void f(T = T()) {} int main() { int n = f(); // equivalent to f<int>() or f(0); return 0; } 

#2 means the following code is illegal:

 template <class T> struct X { template <class U = T> void f(U a = U()) {} }; int main() { X<int> x; xf(); // illegal, though I think it should be equivalent to xf<int>() or xf(0) return 0; } 

I'm just wondering why the latter should be explicitly defined as illegal by the standard?

What is the rationale?

+4
source share
1 answer

I may be mistaken, but my understanding of #2 is that it makes the following illegal:

 template<class T> struct A { void foo(); }; template<class T = int> void A<T>::foo() { /* ... */ } 
+3
source

All Articles