﻿<?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++博客-       [HORSETAIL]-随笔分类-学习随笔</title><link>http://www.cppblog.com/horsetail/category/3493.html</link><description>花儿,总会有谢的时候</description><language>zh-cn</language><lastBuildDate>Mon, 26 May 2008 08:42:06 GMT</lastBuildDate><pubDate>Mon, 26 May 2008 08:42:06 GMT</pubDate><ttl>60</ttl><item><title>重载操作符  -&gt;</title><link>http://www.cppblog.com/horsetail/archive/2007/02/05/18386.html</link><dc:creator>[HORSETAIL]</dc:creator><author>[HORSETAIL]</author><pubDate>Mon, 05 Feb 2007 05:17:00 GMT</pubDate><guid>http://www.cppblog.com/horsetail/archive/2007/02/05/18386.html</guid><wfw:comment>http://www.cppblog.com/horsetail/comments/18386.html</wfw:comment><comments>http://www.cppblog.com/horsetail/archive/2007/02/05/18386.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/horsetail/comments/commentRss/18386.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/horsetail/services/trackbacks/18386.html</trackback:ping><description><![CDATA[         箭头操作符与其他的操作符不同,它可能表现的与二元操作符一样: 接受一个对象和一个成员名,对对像进行解引用.但是不管怎么样,箭头操作符不接受显式形参.<br />       如:<br /><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"><span style="COLOR: #008080"> 1</span> <span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> A{<br /></span><span style="COLOR: #008080"> 2</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080"> 3</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> why(){</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> ;}<br /></span><span style="COLOR: #008080"> 4</span> <span style="COLOR: #000000">a </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">()</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">{</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">;}<br /></span><span style="COLOR: #008080"> 5</span> <span style="COLOR: #000000">};<br /></span><span style="COLOR: #008080"> 6</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 7</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main()<br /></span><span style="COLOR: #008080"> 8</span> <span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080"> 9</span> <span style="COLOR: #000000">   A   Pos;<br /></span><span style="COLOR: #008080">10</span> <span style="COLOR: #000000">   Pos</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">why();  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">展开后: Pos.operator-&gt;()-&gt;why()</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">11</span> <span style="COLOR: #008000"></span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">12</span> <span style="COLOR: #000000">}<br /></span><span style="COLOR: #008080">13</span> <span style="COLOR: #000000"></span></div><br />可以看出,在运用了自定义的箭头操作符后,编译器还会暗地里为我们运行一次箭头操作符.为此,我们在自定义操作符的时候,函数返回类型应该是类的指针或者具有自定义类的类!!我想,这也是自定义箭头操作符的约束吧!!1<img src ="http://www.cppblog.com/horsetail/aggbug/18386.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/horsetail/" target="_blank">[HORSETAIL]</a> 2007-02-05 13:17 <a href="http://www.cppblog.com/horsetail/archive/2007/02/05/18386.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>2007/1/21做的一个日期类!总觉得哪里还有点神秘问题!!</title><link>http://www.cppblog.com/horsetail/archive/2007/01/21/17854.html</link><dc:creator>[HORSETAIL]</dc:creator><author>[HORSETAIL]</author><pubDate>Sun, 21 Jan 2007 03:37:00 GMT</pubDate><guid>http://www.cppblog.com/horsetail/archive/2007/01/21/17854.html</guid><wfw:comment>http://www.cppblog.com/horsetail/comments/17854.html</wfw:comment><comments>http://www.cppblog.com/horsetail/archive/2007/01/21/17854.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/horsetail/comments/commentRss/17854.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/horsetail/services/trackbacks/17854.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">
				<span style="COLOR: #008080"> 1</span> <span style="COLOR: #000000">#ifndef LinBaseDate_<br /></span><span style="COLOR: #008080"> 2</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000"> LinBaseDate_</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 3</span> <span style="COLOR: #000000">#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 4</span> <span style="COLOR: #000000">#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 5</span> <span style="COLOR: #000000">#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">LinSpace.H</span><span style="COLOR: #000000">&gt;   //可省去</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 6</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> LinSpace{<br /></span><span style="COLOR: #008080"> 7</span> <span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> CBaseDate{<br /></span><span style="COLOR: #008080"> 8</span> <span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080"> 9</span> <span style="COLOR: #000000">   std::vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> m_vYear;<br /></span><span style="COLOR: #008080">10</span> <span style="COLOR: #000000">   std::vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> m_vMonth;<br /></span><span style="COLOR: #008080">11</span> <span style="COLOR: #000000">   std::vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> m_vDday;<br /></span><span style="COLOR: #008080">12</span> <span style="COLOR: #000000">   </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080">13</span> <span style="COLOR: #000000">    CBaseDate(){}<br /></span><span style="COLOR: #008080">14</span> <span style="COLOR: #000000">     CBaseDate(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> std::vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> sYear,</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> std::vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> sMonth,</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> std::vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> sDay):<br /></span><span style="COLOR: #008080">15</span> <span style="COLOR: #000000">    m_vYear(sYear.begin(),sYear.end()),m_vMonth(sMonth.begin(),sMonth.end()),m_vDday(sDay.begin(),sDay.end()){}<br /></span><span style="COLOR: #008080">16</span> <span style="COLOR: #000000">     std::vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> GetYear(){ </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> m_vYear;}<br /></span><span style="COLOR: #008080">17</span> <span style="COLOR: #000000">     std::vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> GetDay(){</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> m_vDday;}<br /></span><span style="COLOR: #008080">18</span> <span style="COLOR: #000000">     std::vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> GetMonth(){</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> m_vMonth;} <br /></span><span style="COLOR: #008080">19</span> <span style="COLOR: #000000">   };</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">end class CBaseDate{</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">20</span> <span style="COLOR: #008000"></span><span style="COLOR: #000000">} </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">end namespace LinSpace</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">21</span> <span style="COLOR: #008000"></span><span style="COLOR: #0000ff">#endif</span></div>
		<br />//觉得还有点什么问题似的,但又没想出来!<img src ="http://www.cppblog.com/horsetail/aggbug/17854.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/horsetail/" target="_blank">[HORSETAIL]</a> 2007-01-21 11:37 <a href="http://www.cppblog.com/horsetail/archive/2007/01/21/17854.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>数组不可赋值和直接复制(包括初始化)</title><link>http://www.cppblog.com/horsetail/archive/2007/01/21/17853.html</link><dc:creator>[HORSETAIL]</dc:creator><author>[HORSETAIL]</author><pubDate>Sun, 21 Jan 2007 02:41:00 GMT</pubDate><guid>http://www.cppblog.com/horsetail/archive/2007/01/21/17853.html</guid><wfw:comment>http://www.cppblog.com/horsetail/comments/17853.html</wfw:comment><comments>http://www.cppblog.com/horsetail/archive/2007/01/21/17853.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/horsetail/comments/commentRss/17853.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/horsetail/services/trackbacks/17853.html</trackback:ping><description><![CDATA[      刚刚做练习时犯了个傻B问题-----试图将一个数组去初始化另一个数组!<br />      与vector不同,一个数组不能用另一个数组初始化,也不能将一个数组赋值给另一个数组.(摘自:&lt;C++Primer&gt;)<br />        不过,据了解,某些编译器允许将数组赋值作为编译器扩展,但如果希望自己所编写的程序可以在不同的机器上运行,最好还是遵守标准的规则微妙!!!<br /><img src ="http://www.cppblog.com/horsetail/aggbug/17853.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/horsetail/" target="_blank">[HORSETAIL]</a> 2007-01-21 10:41 <a href="http://www.cppblog.com/horsetail/archive/2007/01/21/17853.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>