大家好, 最近剛好翻到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') ; //<