A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B_Tutorial%2Ftemplate%2Foverload_template_function</id>
		<title>C++ Tutorial/template/overload template function - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B_Tutorial%2Ftemplate%2Foverload_template_function"/>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B_Tutorial/template/overload_template_function&amp;action=history"/>
		<updated>2026-04-11T02:16:27Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B_Tutorial/template/overload_template_function&amp;diff=2611&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B_Tutorial/template/overload_template_function&amp;diff=2611&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:17Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B_Tutorial/template/overload_template_function&amp;diff=2612&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B_Tutorial/template/overload_template_function&amp;diff=2612&amp;oldid=prev"/>
				<updated>2010-05-25T10:30:06Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Overload generic method and non-generic method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include&amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include&amp;lt;string.h&amp;gt;&lt;br /&gt;
template&amp;lt;class T&amp;gt;&lt;br /&gt;
T min(T a,T b)&lt;br /&gt;
{&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;generic&amp;quot;;&lt;br /&gt;
       return (a&amp;lt;b?a:b);&lt;br /&gt;
}&lt;br /&gt;
char *min(char *a,char *b)&lt;br /&gt;
{&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;not generic&amp;quot;;&lt;br /&gt;
       return (strcmp(a,b)&amp;lt;0?a:b);&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  double a=3.56,b=8.23;&lt;br /&gt;
  char s1[]=&amp;quot;Hello&amp;quot;,s2[]=&amp;quot;Good&amp;quot;;&lt;br /&gt;
  cout&amp;lt;&amp;lt;min(a,b)&amp;lt;&amp;lt;endl;&lt;br /&gt;
  cout&amp;lt;&amp;lt;min(s1,s2)&amp;lt;&amp;lt;endl;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;generic3.56&lt;br /&gt;
not genericGood&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using an overloaded function template==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
template&amp;lt;class T&amp;gt; T larger(T a, T b);&lt;br /&gt;
long* larger(long* a, long* b);&lt;br /&gt;
template &amp;lt;class T&amp;gt; T larger (const T array[], int count); // Overloaded templat&lt;br /&gt;
e prototype&lt;br /&gt;
int main() {&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Larger of 1.5 and 2.5 is &amp;quot; &amp;lt;&amp;lt; larger(1.5, 2.5) &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Larger of 3.5 and 4.5 is &amp;quot; &amp;lt;&amp;lt; larger(3.5, 4.5) &amp;lt;&amp;lt; endl;&lt;br /&gt;
 &lt;br /&gt;
  int a_int = 35;&lt;br /&gt;
  int b_int = 45;&lt;br /&gt;
  cout &amp;lt;&amp;lt; larger(a_int, b_int)&amp;lt;&amp;lt; endl;&lt;br /&gt;
  &lt;br /&gt;
  long a_long = 9;&lt;br /&gt;
  long b_long = 8;&lt;br /&gt;
  cout &amp;lt;&amp;lt; larger(a_long, b_long)&amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; *larger(&amp;amp;a_long,&amp;amp;b_long)&amp;lt;&amp;lt; endl;&lt;br /&gt;
  double x[] = { 10.5, 12.5, 2.5, 13.5, 5.5 };&lt;br /&gt;
  cout &amp;lt;&amp;lt; larger(x, sizeof x/sizeof x[0]) &amp;lt;&amp;lt; endl;&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
template &amp;lt;class T&amp;gt; T larger(T a, T b) {&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;standard version &amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return a&amp;gt;b ? a : b;&lt;br /&gt;
}&lt;br /&gt;
long* larger(long* a, long* b) {&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;overloaded version for long* &amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return *a&amp;gt;*b ? a : b;&lt;br /&gt;
}&lt;br /&gt;
template &amp;lt;class T&amp;gt; T larger (const T array[], int count) {&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;template overload version for arrays &amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
  T result = array[0];&lt;br /&gt;
  for(int i = 1 ; i &amp;lt; count ; i++)&lt;br /&gt;
    if(array[i] &amp;gt; result)&lt;br /&gt;
      result = array[i];&lt;br /&gt;
  return result;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;standard version&lt;br /&gt;
Larger of 1.5 and 2.5 is 2.5&lt;br /&gt;
standard version&lt;br /&gt;
Larger of 3.5 and 4.5 is 4.5&lt;br /&gt;
standard version&lt;br /&gt;
45&lt;br /&gt;
standard version&lt;br /&gt;
9&lt;br /&gt;
overloaded version for long*&lt;br /&gt;
9&lt;br /&gt;
template overload version for arrays&lt;br /&gt;
13.5&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using function template specialization==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
template&amp;lt;class T&amp;gt; T larger(T a, T b);             // Function template prototyp&lt;br /&gt;
e&lt;br /&gt;
template&amp;lt;&amp;gt; long* larger&amp;lt;long*&amp;gt;(long* a, long* b); // Specialization&lt;br /&gt;
int main() {&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Larger of 1.5 and 2.5 is &amp;quot; &amp;lt;&amp;lt; larger(1.5, 2.5) &amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Larger of 3.5 and 4.5 is &amp;quot; &amp;lt;&amp;lt; larger(3.5, 4.5) &amp;lt;&amp;lt; endl;&lt;br /&gt;
 &lt;br /&gt;
  int a_int = 35;&lt;br /&gt;
  int b_int = 45;&lt;br /&gt;
  cout &amp;lt;&amp;lt; larger(a_int, b_int)&amp;lt;&amp;lt; endl;&lt;br /&gt;
 &lt;br /&gt;
  long a_long = 9;&lt;br /&gt;
  long b_long = 8;&lt;br /&gt;
  cout &amp;lt;&amp;lt; larger(a_long, b_long)&amp;lt;&amp;lt; endl;&lt;br /&gt;
  cout &amp;lt;&amp;lt; *larger(&amp;amp;a_long,&amp;amp;b_long)&amp;lt;&amp;lt; endl;&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
template &amp;lt;class T&amp;gt; T larger(T a, T b) {&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;standard version &amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return a&amp;gt;b ? a : b;&lt;br /&gt;
}&lt;br /&gt;
template &amp;lt;&amp;gt; long* larger&amp;lt;long*&amp;gt;(long* a, long* b) {&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;specialized version &amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return *a&amp;gt;*b ? a : b;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;standard version&lt;br /&gt;
Larger of 1.5 and 2.5 is 2.5&lt;br /&gt;
standard version&lt;br /&gt;
Larger of 3.5 and 4.5 is 4.5&lt;br /&gt;
standard version&lt;br /&gt;
45&lt;br /&gt;
standard version&lt;br /&gt;
9&lt;br /&gt;
specialized version&lt;br /&gt;
9&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>