c++ - help with explicit template especialization -


I am thankful for getting this example from my book but I can not understand why the line

  S & lt; Zero, interval & gt; Sv; // (2)  

on the template but

  S < Zero, four> E2; // (1) When it is thinking that it is used (2) especially in particular  

Can anyone explain the behavior? BTW All the comments in the code below are from book authors

Thank you very much!

  template & lt; Typename T & gt; Class type {public: typedfed I; }; Template & lt; Typename T, typename u = typename type & lt; T & gt; :: I & gt; Class S; // (1) template & lt; & Gt; Class S & lt; Zero & gt; {// (2) public: zero F (); }; The template's & lt; & Gt; Class S & lt; Four, four & gt; {}; // (3) template & lt; & Gt; Class S & lt; Char, 0> // Error: 0 You can not change the location of main () (S> int> * pi; // OK: Uses (1), no definition is required S & lt; int & Gt; E1; // Error: Usage (1), but no definition is available S & lt; zero & gt; * pv; // OK: Uses (2) S & lt; zero, difference & gt; Sv; // OK: Usage (2), Definition available S & LT; zero, four> E2; // OK: Uses (1), Definition available S & lt; char, char & gt; E3; // error: usage (3), but no definition is available)    

Why should it (2) ?

(2) is used by S & lt; Void, int & gt; is a specialization. What do you have S & lt; Void, char & gt; Types are different, so expertise is not used. Experts apply only when they match exactly It is not good enough that "one can be indirectly promoted to an integer" if S < Void, char & gt; If no specialization is present for , then it will use a normal, nonspecialized version.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -