<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta name="generator" content="pdf2htmlEX">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="https://static.pudn.com/base/css/base.min.css">
<link rel="stylesheet" href="https://static.pudn.com/base/css/fancy.min.css">
<link rel="stylesheet" href="https://static.pudn.com/prod/directory_preview_static/626d3b787b37011214cd1330/raw.css">
<script src="https://static.pudn.com/base/js/compatibility.min.js"></script>
<script src="https://static.pudn.com/base/js/pdf2htmlEX.min.js"></script>
<script>
try{
pdf2htmlEX.defaultViewer = new pdf2htmlEX.Viewer({});
}catch(e){}
</script>
<title></title>
</head>
<body>
<div id="sidebar" style="display: none">
<div id="outline">
</div>
</div>
<div id="pf1" class="pf w0 h0" data-page-no="1"><div class="pc pc1 w0 h0"><img class="bi x0 y0 w1 h1" alt="" src="https://static.pudn.com/prod/directory_preview_static/626d3b787b37011214cd1330/bg1.jpg"><div class="c x0 y1 w2 h2"><div class="t m0 x1 h3 y2 ff1 fs0 fc0 sc0 ls0 ws0">模板</div><div class="t m0 x2 h4 y3 ff1 fs1 fc0 sc0 ls0 ws0">模板</div><div class="t m0 x1 h3 y2 ff1 fs0 fc0 sc0 ls0 ws0">模板</div></div></div><div class="pi" data-data='{"ctm":[1.333333,0.000000,0.000000,1.333333,0.000000,0.000000]}'></div></div>
</body>
</html>
<div id="pf2" class="pf w0 h0" data-page-no="2"><div class="pc pc2 w0 h0"><img class="bi x0 y0 w1 h1" alt="" src="https://static.pudn.com/prod/directory_preview_static/626d3b787b37011214cd1330/bg2.jpg"><div class="c x0 y1 w2 h2"><div class="t m0 x3 h5 y4 ff1 fs2 fc1 sc0 ls0 ws0">2</div><div class="t m0 x2 h4 y3 ff1 fs1 fc0 sc0 ls0 ws0">模板</div><div class="t m0 x4 h6 y5 ff1 fs3 fc2 sc0 ls0 ws0">函数</div><div class="t m0 x4 h6 y6 ff1 fs3 fc2 sc0 ls0 ws0">模板</div><div class="t m0 x5 h6 y7 ff1 fs3 fc2 sc0 ls0 ws0">实参</div><div class="t m0 x5 h6 y8 ff1 fs3 fc2 sc0 ls0 ws0">省略</div><div class="t m0 x6 h6 y9 ff1 fs3 fc2 sc0 ls0 ws0">类模板</div><div class="t m0 x7 h7 ya ff1 fs4 fc3 sc0 ls0 ws0">本章内容</div><div class="t m0 x8 h6 y5 ff1 fs3 fc2 sc0 ls0 ws0">常规</div><div class="t m0 x8 h6 y6 ff1 fs3 fc2 sc0 ls0 ws0">参数</div><div class="t m0 x9 h6 y7 ff1 fs3 fc2 sc0 ls0 ws0">外部</div><div class="t m0 x9 h6 y8 ff1 fs3 fc2 sc0 ls0 ws0">定义</div><div class="t m0 xa h8 y7 ff2 fs3 fc2 sc0 ls0 ws0">OOP</div><div class="t m0 xa h6 y8 ff1 fs3 fc2 sc0 ls0 ws0">特点</div></div></div><div class="pi" data-data='{"ctm":[1.333333,0.000000,0.000000,1.333333,0.000000,0.000000]}'></div></div>
<div id="pf3" class="pf w0 h0" data-page-no="3"><div class="pc pc3 w0 h0"><img class="bi x0 y0 w1 h1" alt="" src="https://static.pudn.com/prod/directory_preview_static/626d3b787b37011214cd1330/bg3.jpg"><div class="c x0 y1 w2 h2"><div class="t m0 x3 h5 y4 ff1 fs2 fc1 sc0 ls0 ws0"><span class="fc5 sc0">3</span></div><div class="t m0 x2 h4 y3 ff1 fs1 fc0 sc0 ls0 ws0">模板</div><div class="t m0 xb h9 yb ff3 fs0 fc1 sc0 ls0 ws0"><span class="fc5 sc0">i</span><span class="fc5 sc0">n</span><span class="fc5 sc0">t</span><span class="fc5 sc0"> </span><span class="fc5 sc0">m</span><span class="_ _0"></span><span class="fc5 sc0">a</span><span class="fc5 sc0">x</span><span class="fc5 sc0">(</span><span class="fc5 sc0">i</span><span class="fc5 sc0">n</span><span class="_ _0"></span><span class="fc5 sc0">t</span><span class="fc5 sc0"> </span><span class="fc5 sc0">x</span><span class="fc5 sc0">,</span><span class="fc5 sc0"> </span><span class="_ _0"></span><span class="fc5 sc0">i</span><span class="fc5 sc0">n</span><span class="fc5 sc0">t</span><span class="fc5 sc0"> </span><span class="fc5 sc0">y</span><span class="_ _0"></span><span class="fc5 sc0">)</span></div><div class="t m0 xb h9 yc ff3 fs0 fc1 sc0 ls0 ws0"><span class="fc5 sc0">{</span></div><div class="t m0 xb h9 yd ff3 fs0 fc1 sc0 ls0 ws0"><span class="fc5 sc0"> </span><span class="fc5 sc0"> </span><span class="fc5 sc0"> </span><span class="fc5 sc0"> </span><span class="_ _0"></span><span class="fc5 sc0">r</span><span class="fc5 sc0">e</span><span class="fc5 sc0">t</span><span class="fc5 sc0">u</span><span class="fc5 sc0">r</span><span class="_ _0"></span><span class="fc5 sc0">n</span><span class="fc5 sc0"> </span><span class="fc5 sc0">x</span><span class="fc5 sc0"> </span><span class="fc5 sc0">></span><span class="_ _0"></span><span class="fc5 sc0"> </span><span class="fc5 sc0">y</span><span class="fc5 sc0"> </span><span class="fc5 sc0">?</span><span class="fc5 sc0"> </span><span class="_ _0"></span><span class="fc5 sc0">x</span><span class="fc5 sc0"> </span><span class="fc5 sc0">:</span><span class="fc5 sc0"> </span><span class="fc5 sc0">y</span><span class="_ _0"></span><span class="fc5 sc0">;</span></div><div class="t m0 xb h9 ye ff3 fs0 fc1 sc0 ls0 ws0"><span class="fc5 sc0">}</span></div><div class="t m0 xb h9 yf ff3 fs0 fc1 sc0 ls0 ws0"><span class="fc5 sc0">d</span><span class="fc5 sc0">o</span><span class="fc5 sc0">u</span><span class="fc5 sc0">b</span><span class="fc5 sc0">l</span><span class="_ _0"></span><span class="fc5 sc0">e</span><span class="fc5 sc0"> </span><span class="fc5 sc0">m</span><span class="fc5 sc0">a</span><span class="fc5 sc0">x</span><span class="_ _0"></span><span class="fc5 sc0">(</span><span class="fc5 sc0">d</span><span class="fc5 sc0">o</span><span class="fc5 sc0">u</span><span class="fc5 sc0">b</span><span class="_ _0"></span><span class="fc5 sc0">l</span><span class="fc5 sc0">e</span><span class="fc5 sc0"> </span><span class="fc5 sc0">x</span><span class="fc5 sc0">,</span><span class="_ _0"></span><span class="fc5 sc0"> </span><span class="fc5 sc0">d</span><span class="fc5 sc0">o</span><span class="fc5 sc0">u</span><span class="fc5 sc0">b</span><span class="_ _0"></span><span class="fc5 sc0">l</span><span class="fc5 sc0">e</span><span class="fc5 sc0"> </span></div><div class="t m0 xb h9 y10 ff3 fs0 fc1 sc0 ls0 ws0"><span class="fc5 sc0">y</span><span class="fc5 sc0">)</span></div><div class="t m0 xb h9 y11 ff3 fs0 fc1 sc0 ls0 ws0"><span class="fc5 sc0">{</span></div><div class="t m0 xb h9 y12 ff3 fs0 fc1 sc0 ls0 ws0"><span class="fc5 sc0"> </span><span class="fc5 sc0"> </span><span class="fc5 sc0"> </span><span class="fc5 sc0"> </span><span class="_ _0"></span><span class="fc5 sc0">r</span><span class="fc5 sc0">e</span><span class="fc5 sc0">t</span><span class="fc5 sc0">u</span><span class="fc5 sc0">r</span><span class="_ _0"></span><span class="fc5 sc0">n</span><span class="fc5 sc0"> </span><span class="fc5 sc0">x</span><span class="fc5 sc0"> </span><span class="fc5 sc0">></span><span class="_ _0"></span><span class="fc5 sc0"> </span><span class="fc5 sc0">y</span><span class="fc5 sc0"> </span><span class="fc5 sc0">?</span><span class="fc5 sc0"> </span><span class="_ _0"></span><span class="fc5 sc0">x</span><span class="fc5 sc0"> </span><span class="fc5 sc0">:</span><span class="fc5 sc0"> </span><span class="fc5 sc0">y</span><span class="_ _0"></span><span class="fc5 sc0">;</span></div><div class="t m0 xb h9 y13 ff3 fs0 fc1 sc0 ls0 ws0">}</div><div class="t m0 xb h9 y14 ff3 fs0 fc1 sc0 ls0 ws0">templ<span class="_ _0"></span>ate <<span class="_ _0"></span>class<span class="_ _0"></span> <span class="fc4">T</span>></div><div class="t m0 xb h9 y15 ff3 fs0 fc4 sc0 ls0 ws0">T<span class="fc1"> max<span class="_ _0"></span>(<span class="fc4">T</span> x<span class="_ _0"></span>, <span class="fc4">T</span> y<span class="_ _0"></span>)</span></div><div class="t m0 xb h9 y16 ff3 fs0 fc1 sc0 ls0 ws0">{</div><div class="t m0 xb h9 y17 ff3 fs0 fc1 sc0 ls0 ws0"> <span class="_ _0"></span>retur<span class="_ _0"></span>n x ><span class="_ _0"></span> y ? <span class="_ _0"></span>x : y<span class="_ _0"></span>;</div><div class="t m0 xb h9 y18 ff3 fs0 fc1 sc0 ls0 ws0">}</div><div class="t m0 xc ha y19 ff4 fs3 fc1 sc1 ls0 ws0">模板函数参数</div><div class="t m0 xb hb y1a ff4 fs0 fc1 sc1 ls0 ws0">对于函数模板,<span class="_ _0"></span>数据类型本<span class="_ _0"></span>身成了它的参</div><div class="t m0 xb hb y1b ff4 fs0 fc1 sc1 ls0 ws0">数,因而是一种<span class="_ _0"></span>参数化类型<span class="_ _0"></span>的函数。</div><div class="t m0 xb hb y1c ff4 fs0 fc1 sc1 ls0 ws0">函数模板是生成<span class="_ _0"></span>函数的函数<span class="_ _0"></span>。</div><div class="t m0 xb hb y1d ff4 fs0 fc1 sc1 ls0 ws0">格式:</div><div class="t m0 xb hb y1e ff3 fs0 fc1 sc0 ls0 ws0">templ<span class="_ _0"></span>ate <<span class="_ _1"> </span><span class="ff4 sc1">模板形参表<span class="_ _1"> </span></span>> <span class="_ _2"> </span><span class="ff4 sc1">函数定义</span></div><div class="t m0 xb hb y1f ff4 fs0 fc1 sc1 ls0 ws0">举例:</div><div class="t m0 xd ha y20 ff4 fs3 fc1 sc1 ls0 ws0">模板参数</div><div class="t m0 x4 h6 y21 ff1 fs3 fc2 sc0 ls0 ws0">函数</div><div class="t m0 x4 h6 y22 ff1 fs3 fc2 sc0 ls0 ws0">模板</div><div class="t m0 x7 h7 ya ff1 fs4 fc3 sc0 ls0 ws0">函数模板</div></div></div><div class="pi" data-data='{"ctm":[1.333333,0.000000,0.000000,1.333333,0.000000,0.000000]}'></div></div>