Created on 2013-04-19.00:00:00 last changed 143 months ago
Additional note, January, 2014:
A related example has been raised:
template<typename T> class Matrix {
public:
Matrix(){}
Matrix(const Matrix&){}
template<typename U>
Matrix(const Matrix<U>&);
};
template Matrix<int>::Matrix(const Matrix&);
Matrix<int> m;
Matrix<int> mm(m);
If the explicit instantiation directive applies to the constructor template, there is no way to explicitly instantiate the copy constructor.
Consider a case like
struct X {
template<typename T> void f(T);
void f(int);
};
template void X::f(int);
or
template<typename T> void f(T) {}
void f(int);
template void f(int);
Presumably in both these cases the explicit instantiation should refer to the template and not to the non-template; however, 13.7.3 [temp.mem] paragraph 2 says,
A normal (non-template) member function with a given name and type and a member function template of the same name, which could be used to generate a specialization of the same type, can both be declared in a class. When both exist, a use of that name and type refers to the non-template member unless an explicit template argument list is supplied.
This would appear to give the wrong answer for the first example. It's not clearly stated, but consistency would suggest a similar wrong answer for the second. Presumably a statement is needed somewhere that an explicit instantiation directive applies to a template and not a non-template function if both are visible.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2014-01-20 00:00:00 | admin | set | messages: + msg4747 |
| 2013-10-14 00:00:00 | admin | set | status: open -> drafting |
| 2013-04-19 00:00:00 | admin | create | |