大家好, 最近刚好翻到the C++ programming language,章节C.13.8.4
有关templates, namespace 跟 specialization的, 看不太懂他所要表达的意思.
首先呢, 上面提到:
.......省略.......
This reflects three obvious strategies an implementation can use for
generating specializations:
[1] Generate a specialization the first time a call is seen.
[2] At the end of a translation unit, generate all specializations needed for
that translation unit.
[3] Once every translation unit of a program has been seen, generate all
specializations needed for the program.
All three strategies have strengths and weaknesses, and combinations of these
strategies are also possible.
......省略.......
然后说:
A program is illegal, if it is possible to construct two different meanings
by choosing different points of instantiation or different contents of
namespaces at different possible contexts for generating the specialization.
然后有一段范例码:
namespace N
{
class A{ /* ... */ };
char f(A,int) ;
}
template<class T, class T2> char g(T t, T2 t2) { return f(t,t2) ; }
//error (alternative resolutions of f(t))
char c= g(N: :A() ,'a') ; //<