Skip to content

Commit

Permalink
Site updated: 2020-07-17 20:52:04
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinkle-hzt committed Jul 17, 2020
1 parent a68a752 commit c560019
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions 2020/07/17/cpp-template-2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@

<p class="note note-info">

本文最后更新于:2020年7月17日 下午
本文最后更新于:2020年7月17日 晚上

</p>

Expand Down Expand Up @@ -849,7 +849,7 @@ <h3 id="类模板对字符串常量的参数推导:"><a href="#类模板对字
<pre><code class="hljs c++">Stack&lt;<span class="hljs-keyword">char</span> <span class="hljs-keyword">const</span>[<span class="hljs-number">7</span>]&gt;</code></pre>

<p>当使用 <code>T</code> 的时候都会被实例化为 <code>char const[7]</code>。这样我们就不能放入不同长度的字符串了,因为这是不同的类型。详细的讨论<a href>参见 7.4 节(未写)</a></p>
<p>但是,如果我们按值传递模板参数 <code>T</code> 的话,参数类型就会被 <em>decay*,也就是将 *raw array</em> 转换为相应的 <em>raw pointer<em>。这样,调用带有模板参数 <code>T</code> 的构造函数就会将模板参数 <code>T</code> 的类型推导成 `char const</em><code>,模板也被推导为</code>Stack&lt;char const</em>&gt;`</p>
<p>但是,如果我们按值传递模板参数 <code>T</code> 的话,参数类型就会被 <em>decay</em> ,也就是将 <em>raw array</em> 转换为相应的 <em>raw pointer</em> 。这样,调用带有模板参数 <code>T</code> 的构造函数就会将模板参数 <code>T</code> 的类型推导成 <code>char const*</code>,模板也被推导为 <code>Stack&lt;char const*&gt;</code></p>
<p>基于以上原因,可能有必要讲构造函数声明成按值传递参数的形式:</p>
<pre><code class="hljs c++"><span class="hljs-keyword">template</span> &lt;<span class="hljs-keyword">typename</span> T&gt;
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Stack</span> </span>
Expand Down
30 changes: 15 additions & 15 deletions categories/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
<div class="category row">
<a
class="category-item list-group-item category-item-action col-10 col-md-11"
id="heading-ckcpsdtlo000350vp2mvt0yap" role="tab" data-toggle="collapse" href="#collapse-ckcpsdtlo000350vp2mvt0yap"
id="heading-ckcq80thw00046ovpaxjad022" role="tab" data-toggle="collapse" href="#collapse-ckcq80thw00046ovpaxjad022"
aria-expanded="true"
>
C++
Expand All @@ -200,8 +200,8 @@
<div class="category-collapse">


<div id="collapse-ckcpsdtlo000350vp2mvt0yap" class="collapse in show" role="tabpanel"
aria-labelledby="heading-ckcpsdtlo000350vp2mvt0yap">
<div id="collapse-ckcq80thw00046ovpaxjad022" class="collapse in show" role="tabpanel"
aria-labelledby="heading-ckcq80thw00046ovpaxjad022">



Expand All @@ -210,7 +210,7 @@
<div class="category-sub row">
<a
class="category-subitem collapsed list-group-item category-item-action col-10 col-md-11"
id="heading-ckcpsdtlv000h50vph6i153hc" role="tab" data-toggle="collapse" href="#collapse-ckcpsdtlv000h50vph6i153hc"
id="heading-ckcq80thx00096ovp09eg226i" role="tab" data-toggle="collapse" href="#collapse-ckcq80thx00096ovp09eg226i"
aria-expanded="false"
>
Template
Expand All @@ -223,8 +223,8 @@
<div class="category-collapse">


<div id="collapse-ckcpsdtlv000h50vph6i153hc" class="collapse in" role="tabpanel"
aria-labelledby="heading-ckcpsdtlv000h50vph6i153hc">
<div id="collapse-ckcq80thx00096ovp09eg226i" class="collapse in" role="tabpanel"
aria-labelledby="heading-ckcq80thx00096ovp09eg226i">



Expand Down Expand Up @@ -253,7 +253,7 @@
<div class="category-sub row">
<a
class="category-subitem collapsed list-group-item category-item-action col-10 col-md-11"
id="heading-ckcpsdtmm001750vpgdh9hfud" role="tab" data-toggle="collapse" href="#collapse-ckcpsdtmm001750vpgdh9hfud"
id="heading-ckcq80tk900186ovp51ws5vzp" role="tab" data-toggle="collapse" href="#collapse-ckcq80tk900186ovp51ws5vzp"
aria-expanded="false"
>
杂项
Expand All @@ -266,8 +266,8 @@
<div class="category-collapse">


<div id="collapse-ckcpsdtmm001750vpgdh9hfud" class="collapse in" role="tabpanel"
aria-labelledby="heading-ckcpsdtmm001750vpgdh9hfud">
<div id="collapse-ckcq80tk900186ovp51ws5vzp" class="collapse in" role="tabpanel"
aria-labelledby="heading-ckcq80tk900186ovp51ws5vzp">



Expand Down Expand Up @@ -295,7 +295,7 @@
<div class="category row">
<a
class="category-item collapsed list-group-item category-item-action col-10 col-md-11"
id="heading-ckcpsdtls000750vpf8eob5qz" role="tab" data-toggle="collapse" href="#collapse-ckcpsdtls000750vpf8eob5qz"
id="heading-ckcq80thu00026ovphrzr6yyg" role="tab" data-toggle="collapse" href="#collapse-ckcq80thu00026ovphrzr6yyg"
aria-expanded="false"
>
CSAPP
Expand All @@ -308,8 +308,8 @@
<div class="category-collapse">


<div id="collapse-ckcpsdtls000750vpf8eob5qz" class="collapse in" role="tabpanel"
aria-labelledby="heading-ckcpsdtls000750vpf8eob5qz">
<div id="collapse-ckcq80thu00026ovphrzr6yyg" class="collapse in" role="tabpanel"
aria-labelledby="heading-ckcq80thu00026ovphrzr6yyg">



Expand Down Expand Up @@ -338,7 +338,7 @@
<div class="category row">
<a
class="category-item collapsed list-group-item category-item-action col-10 col-md-11"
id="heading-ckcpsdtmg000r50vp5hbkdp6w" role="tab" data-toggle="collapse" href="#collapse-ckcpsdtmg000r50vp5hbkdp6w"
id="heading-ckcq80tiq000l6ovpaas42ngb" role="tab" data-toggle="collapse" href="#collapse-ckcq80tiq000l6ovpaas42ngb"
aria-expanded="false"
>
算法
Expand All @@ -351,8 +351,8 @@
<div class="category-collapse">


<div id="collapse-ckcpsdtmg000r50vp5hbkdp6w" class="collapse in" role="tabpanel"
aria-labelledby="heading-ckcpsdtmg000r50vp5hbkdp6w">
<div id="collapse-ckcq80tiq000l6ovpaas42ngb" class="collapse in" role="tabpanel"
aria-labelledby="heading-ckcq80tiq000l6ovpaas42ngb">



Expand Down
2 changes: 1 addition & 1 deletion local-search.xml

Large diffs are not rendered by default.

0 comments on commit c560019

Please sign in to comment.