﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-海阔凭鱼跃-文章分类-STL</title><link>http://www.cppblog.com/fishyumiao/category/17020.html</link><description>小鱼的博客</description><language>zh-cn</language><lastBuildDate>Sat, 04 Jun 2011 04:00:38 GMT</lastBuildDate><pubDate>Sat, 04 Jun 2011 04:00:38 GMT</pubDate><ttl>60</ttl><item><title>STL模板函数的继承</title><link>http://www.cppblog.com/fishyumiao/articles/147763.html</link><dc:creator>yumiao</dc:creator><author>yumiao</author><pubDate>Tue, 31 May 2011 08:59:00 GMT</pubDate><guid>http://www.cppblog.com/fishyumiao/articles/147763.html</guid><wfw:comment>http://www.cppblog.com/fishyumiao/comments/147763.html</wfw:comment><comments>http://www.cppblog.com/fishyumiao/articles/147763.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/fishyumiao/comments/commentRss/147763.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/fishyumiao/services/trackbacks/147763.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdio.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdlib.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />template</span><span style="color: #000000">&lt;</span><span style="color: #000000">typename&nbsp;Item</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;HIFState<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img id="Codehighlighter1_79_150_Open_Image" onclick="this.style.display='none'; Codehighlighter1_79_150_Open_Text.style.display='none'; Codehighlighter1_79_150_Closed_Image.style.display='inline'; Codehighlighter1_79_150_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_79_150_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_79_150_Closed_Text.style.display='none'; Codehighlighter1_79_150_Open_Image.style.display='inline'; Codehighlighter1_79_150_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_79_150_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_79_150_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">virtual</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">~</span><span style="color: #000000">HIFState()<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img id="Codehighlighter1_111_114_Open_Image" onclick="this.style.display='none'; Codehighlighter1_111_114_Open_Text.style.display='none'; Codehighlighter1_111_114_Closed_Image.style.display='inline'; Codehighlighter1_111_114_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_111_114_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_111_114_Closed_Text.style.display='none'; Codehighlighter1_111_114_Open_Image.style.display='inline'; Codehighlighter1_111_114_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_111_114_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_111_114_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">11</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /></span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;Item&nbsp;m_evaValue;</span><span style="color: #008000">//</span><span style="color: #008000">目标函数值</span><span style="color: #008000"><br /></span><span style="color: #008080">14</span><span style="color: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" /></span><span style="color: #000000">}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /></span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />template</span><span style="color: #000000">&lt;</span><span style="color: #000000">typename&nbsp;State</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">17</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;HIFComparator<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img id="Codehighlighter1_199_276_Open_Image" onclick="this.style.display='none'; Codehighlighter1_199_276_Open_Text.style.display='none'; Codehighlighter1_199_276_Closed_Image.style.display='inline'; Codehighlighter1_199_276_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_199_276_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_199_276_Closed_Text.style.display='none'; Codehighlighter1_199_276_Open_Image.style.display='inline'; Codehighlighter1_199_276_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_199_276_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_199_276_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">virtual</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;Compare(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;State</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;item1,&nbsp;</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;State</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;item2)&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /></span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" />template</span><span style="color: #000000">&lt;</span><span style="color: #000000">typename&nbsp;Item</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;HIFStateComparator&nbsp;:&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;HIFComparator</span><span style="color: #000000">&lt;</span><span style="color: #000000">HIFState</span><span style="color: #000000">&lt;</span><span style="color: #000000">Item</span><span style="color: #000000">&gt;*&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">25</span><span style="color: #000000"><img id="Codehighlighter1_369_582_Open_Image" onclick="this.style.display='none'; Codehighlighter1_369_582_Open_Text.style.display='none'; Codehighlighter1_369_582_Closed_Image.style.display='inline'; Codehighlighter1_369_582_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_369_582_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_369_582_Closed_Text.style.display='none'; Codehighlighter1_369_582_Open_Image.style.display='inline'; Codehighlighter1_369_582_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_369_582_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_369_582_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">:<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;typedef&nbsp;typename&nbsp;HIFState</span><span style="color: #000000">&lt;</span><span style="color: #000000">Item</span><span style="color: #000000">&gt;*</span><span style="color: #000000">&nbsp;State;<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">virtual</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;Compare(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;State</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;item1,&nbsp;</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;State</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;item2)<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img id="Codehighlighter1_483_580_Open_Image" onclick="this.style.display='none'; Codehighlighter1_483_580_Open_Text.style.display='none'; Codehighlighter1_483_580_Closed_Image.style.display='inline'; Codehighlighter1_483_580_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top"><img id="Codehighlighter1_483_580_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_483_580_Closed_Text.style.display='none'; Codehighlighter1_483_580_Open_Image.style.display='inline'; Codehighlighter1_483_580_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_483_580_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_483_580_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">HIFStateComparator-&gt;Compare\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">31</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;(item1</span><span style="color: #000000">-&gt;</span><span style="color: #000000">m_evaValue&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;item2</span><span style="color: #000000">-&gt;</span><span style="color: #000000">m_evaValue);<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">33</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /><br /></span><span style="color: #008080">35</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top"  alt="" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img id="Codehighlighter1_598_889_Open_Image" onclick="this.style.display='none'; Codehighlighter1_598_889_Open_Text.style.display='none'; Codehighlighter1_598_889_Closed_Image.style.display='inline'; Codehighlighter1_598_889_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top"><img id="Codehighlighter1_598_889_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_598_889_Closed_Text.style.display='none'; Codehighlighter1_598_889_Open_Image.style.display='inline'; Codehighlighter1_598_889_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top"></span><span id="Codehighlighter1_598_889_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_598_889_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">37</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;HIFState</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">double</span><span style="color: #000000">&gt;*</span><span style="color: #000000">&nbsp;pState1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;HIFState</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">double</span><span style="color: #000000">&gt;</span><span style="color: #000000">;<br /></span><span style="color: #008080">38</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;HIFState</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">double</span><span style="color: #000000">&gt;*</span><span style="color: #000000">&nbsp;pState2&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;HIFState</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">double</span><span style="color: #000000">&gt;</span><span style="color: #000000">;<br /></span><span style="color: #008080">39</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /><br /></span><span style="color: #008080">40</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;HIFComparator</span><span style="color: #000000">&lt;</span><span style="color: #000000">HIFState</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">double</span><span style="color: #000000">&gt;*&gt;*</span><span style="color: #000000">&nbsp;pStateComparator&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;HIFStateComparator</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">double</span><span style="color: #000000">&gt;</span><span style="color: #000000">;<br /></span><span style="color: #008080">41</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;pStateComparator</span><span style="color: #000000">-&gt;</span><span style="color: #000000">Compare(pState1,&nbsp;pState2);<br /></span><span style="color: #008080">42</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span style="color: #008000"><br /></span><span style="color: #008080">43</span><span style="color: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;delete&nbsp;pStateComparator;<br /></span><span style="color: #008080">44</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="color: #000000">"</span><span style="color: #000000">pause</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">45</span><span style="color: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top"  alt="" />}</span></span></div><img src ="http://www.cppblog.com/fishyumiao/aggbug/147763.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/fishyumiao/" target="_blank">yumiao</a> 2011-05-31 16:59 <a href="http://www.cppblog.com/fishyumiao/articles/147763.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>