c++ - Function template overloading (different return value type) -
I am reading, and "13.7 partial specialization of function templates" the author said:
< To overload the P> function template, their function parameters must be different in some physical way. Consider the Function Template R Convert (T const & amp;) where the R and T template parameters are. We want to make this template very well for R = Zero, but this overloading can not be used.
This function can be done using template overloading, right? Like:
  #include & lt; Iostream & gt; Template & lt; Typename t, typename r & gt; R Convert (T const & amp;) {std :: cout & lt; & Lt; "R Convert (T const & amp;) \ n"; } Template & lt; Typename T & gt; Zero changed (T const & amp;) {std :: cout & lt; & Lt; "Zero changed (T const & amp;) \ n"; } Int main () {convert (0); }   Here, the result is:
zero changed (T const & amp;)
the author actually What do you mean Class Template Partial Expertise:
  template     
  U, class V & gt; Square t {}; Template & lt; Class V & gt; Class T & LT; Zero, V & gt; {};   
 When you sign in  T & lt; Void, int & gt; , partial expertise will be used. 
  Now consider the template of the function: 
   template & lt; Typename R, typename T & gt; Convert (T const & amp;) {return / * some * /; }  
  Note that the order of  R  and  T  have been swapped up in the template parameters list. This is probably how a template like this will be written - you convert  ; & Gt; (Some)  , while explicitly specifying the destination type, the source type is estimated by the compiler. 
  Now assume that you want  to separate something  Wanted & gt; You can not do this with a surcharge: 
   template & lt; Typename T & gt; If you type  convert (something)  - which was already going to be ill, then it will go to your new surcharge, because the compiler can not remove  R  for the first template . But if you type , then still go to the original template  or even  convert and  written; Zero, t & gt; (Some)   To make it even worse, change something like  & lt; Int & gt; (1)  is now impaired because it is unclear.   In other words, you use  convert & lt    
 a different implementation ; Int, T & gt; (Some) , while you can do class templates with partial specializations.    / div>  
 
  
 
Comments
Post a Comment