﻿<?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/</link><description>花儿,总会有谢的时候</description><language>zh-cn</language><lastBuildDate>Sat, 04 Apr 2026 09:55:48 GMT</lastBuildDate><pubDate>Sat, 04 Apr 2026 09:55:48 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>3</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></channel></rss>