template <typename T> struct A { A<T> foo (A<T>, A<T>) {return A<T>();} A foo (A,A) {return A();} }; What is the difference between 2 functions?
template <typename T> struct A { A<T> foo (A<T>, A<T>) {return A<T>();} A foo (A,A) {return A();} }; What is the difference between 2 functions?
There is no difference as such. It is just that in one case the template class is explicitly parameterized by the type T , and in the other - implicitly. This can be seen on the appropriate example:
template <typename T> struct A { A<T> foo (A<T>, A<T>) {return A<T>();} A foo (A,A) {return A();} }; int main() { A<int> a; a.foo(a,a); } When compiling , an error will be displayed:
error: class member cannot be redeclared
Those. the compiler found the functions identical.
In this case, the use of a short name in this case is preferable, since does not depend on the change of the name of the template parameter or their count.
In the Language Standard, this moment is described in clause 14.6.1 / 1 :
Like normal (non-template) (in Clause 9). [...] is equivalent to the template-template enclosed in <>.
Source: https://ru.stackoverflow.com/questions/504777/
All Articles