﻿<?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++博客-昵称不能为空-文章分类-C++ Primer Plus 5th Notes</title><link>http://www.cppblog.com/HelloCpp/category/11486.html</link><description /><language>zh-cn</language><lastBuildDate>Mon, 17 Aug 2009 21:53:15 GMT</lastBuildDate><pubDate>Mon, 17 Aug 2009 21:53:15 GMT</pubDate><ttl>60</ttl><item><title>使用类（C++）</title><link>http://www.cppblog.com/HelloCpp/articles/93633.html</link><dc:creator>HellpCpp</dc:creator><author>HellpCpp</author><pubDate>Mon, 17 Aug 2009 10:58:00 GMT</pubDate><guid>http://www.cppblog.com/HelloCpp/articles/93633.html</guid><wfw:comment>http://www.cppblog.com/HelloCpp/comments/93633.html</wfw:comment><comments>http://www.cppblog.com/HelloCpp/articles/93633.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/HelloCpp/comments/commentRss/93633.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/HelloCpp/services/trackbacks/93633.html</trackback:ping><description><![CDATA[
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="ProgId" content="Word.Document" />
		<meta name="Generator" content="Microsoft Word 11" />
		<meta name="Originator" content="Microsoft Word 11" />
		<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" />
		<link rel="Edit-Time-Data" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_editdata.mso" />
		<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
		<o:smarttagtype namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="chsdate" downloadurl="">
		</o:smarttagtype>
		<!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:View>Normal</w:View>
  <w:Zoom>0</w:Zoom>
  <w:PunctuationKerning/>
  <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
  <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
  <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
  <w:ValidateAgainstSchemas/>
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  <w:Compatibility>
   <w:SpaceForUL/>
   <w:BalanceSingleByteDoubleByteWidth/>
   <w:DoNotLeaveBackslashAlone/>
   <w:ULTrailSpace/>
   <w:DoNotExpandShiftReturn/>
   <w:AdjustLineHeightInTable/>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:DontGrowAutofit/>
   <w:UseFELayout/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]-->
		<!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" LatentStyleCount="156">
 </w:LatentStyles>
</xml><![endif]-->
		<!--[if !mso]><object
 classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id=ieooui></object>
<style>
st1\:*{behavior:url(#ieooui) }
</style>
<![endif]-->
		<style>
				<!--
 /* Font Definitions */
 @font-face
	{font-family:Wingdings;
	panose-1:5 0 0 0 0 0 0 0 0 0;
	mso-font-charset:2;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:0 268435456 0 0 -2147483648 0;}
@font-face
	{font-family:宋体;
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-alt:SimSun;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
	{font-family:黑体;
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-alt:SimHei;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:1 135135232 16 0 262144 0;}
@font-face
	{font-family:"\@宋体";
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
	{font-family:"\@黑体";
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:1 135135232 16 0 262144 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0cm;
	margin-bottom:.0001pt;
	text-align:justify;
	text-justify:inter-ideograph;
	mso-pagination:none;
	font-size:10.5pt;
	mso-bidi-font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:宋体;
	mso-font-kerning:1.0pt;}
 /* Page Definitions */
 @page
	{mso-page-border-surround-header:no;
	mso-page-border-surround-footer:no;}
@page Section1
	{size:595.3pt 841.9pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;
	mso-header-margin:42.55pt;
	mso-footer-margin:49.6pt;
	mso-paper-source:0;
	layout-grid:15.6pt;}
div.Section1
	{page:Section1;}
 /* List Definitions */
 @list l0
	{mso-list-id:928737321;
	mso-list-type:hybrid;
	mso-list-template-ids:719640234 67698697 67698689 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
	{mso-level-number-format:bullet;
	mso-level-text:;
	mso-level-tab-stop:21.0pt;
	mso-level-number-position:left;
	margin-left:21.0pt;
	text-indent:-21.0pt;
	font-family:Wingdings;}
@list l0:level2
	{mso-level-number-format:bullet;
	mso-level-text:;
	mso-level-tab-stop:42.0pt;
	mso-level-number-position:left;
	margin-left:42.0pt;
	text-indent:-21.0pt;
	font-family:Wingdings;}
@list l1
	{mso-list-id:2022078338;
	mso-list-type:hybrid;
	mso-list-template-ids:-1269680700 67698689 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l1:level1
	{mso-level-number-format:bullet;
	mso-level-text:;
	mso-level-tab-stop:39.0pt;
	mso-level-number-position:left;
	margin-left:39.0pt;
	text-indent:-21.0pt;
	font-family:Wingdings;}
@list l2
	{mso-list-id:2038383723;
	mso-list-template-ids:1699364836;}
@list l2:level1
	{mso-level-text:%1;
	mso-level-tab-stop:18.0pt;
	mso-level-number-position:left;
	margin-left:18.0pt;
	text-indent:-18.0pt;}
@list l2:level2
	{mso-level-text:"%1\.%2";
	mso-level-tab-stop:18.0pt;
	mso-level-number-position:left;
	margin-left:18.0pt;
	text-indent:-18.0pt;}
@list l2:level3
	{mso-level-text:"%1\.%2\.%3";
	mso-level-tab-stop:36.0pt;
	mso-level-number-position:left;
	margin-left:36.0pt;
	text-indent:-36.0pt;}
@list l2:level4
	{mso-level-text:"%1\.%2\.%3\.%4";
	mso-level-tab-stop:36.0pt;
	mso-level-number-position:left;
	margin-left:36.0pt;
	text-indent:-36.0pt;}
@list l2:level5
	{mso-level-text:"%1\.%2\.%3\.%4\.%5";
	mso-level-tab-stop:54.0pt;
	mso-level-number-position:left;
	margin-left:54.0pt;
	text-indent:-54.0pt;}
@list l2:level6
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6";
	mso-level-tab-stop:54.0pt;
	mso-level-number-position:left;
	margin-left:54.0pt;
	text-indent:-54.0pt;}
@list l2:level7
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7";
	mso-level-tab-stop:72.0pt;
	mso-level-number-position:left;
	margin-left:72.0pt;
	text-indent:-72.0pt;}
@list l2:level8
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8";
	mso-level-tab-stop:72.0pt;
	mso-level-number-position:left;
	margin-left:72.0pt;
	text-indent:-72.0pt;}
@list l2:level9
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.%9";
	mso-level-tab-stop:90.0pt;
	mso-level-number-position:left;
	margin-left:90.0pt;
	text-indent:-90.0pt;}
ol
	{margin-bottom:0cm;}
ul
	{margin-bottom:0cm;}
-->
		</style>
		<!--[if gte mso 10]>
<style>
 /* Style Definitions */
 table.MsoNormalTable
	{mso-style-name:普通表格;
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
	mso-para-margin:0cm;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";
	mso-ansi-language:#0400;
	mso-fareast-language:#0400;
	mso-bidi-language:#0400;}
</style>
<![endif]-->
		<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="2050"/>
</xml><![endif]-->
		<!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1"/>
 </o:shapelayout></xml><![endif]-->
		<p class="MsoNormal">
				<!--[if gte vml 1]><v:line id="_x0000_s1026" style='position:absolute;
 left:0;text-align:left;z-index:1' from="0,39pt" to="441pt,39pt"
 strokeweight="1pt">
 <w:wrap type="square"/>
</v:line><![endif]-->
				<!--[if !vml]-->
				<img src="file:///C:/DOCUME%7E1/ADMINI%7E1/LOCALS%7E1/Temp/msohtml1/01/clip_image001.gif" v:shapes="_x0000_s1026" align="left" width="590" height="2" hspace="12" />
				<!--[endif]-->
				<b style="">
						<i style="">
								<span style="font-size: 18pt; font-family: 宋体;">使用类</span>
						</i>
				</b>
				<b style="">
						<i style="">
								<span style="font-size: 18pt;" lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</i>
				</b>
		</p>
		<p class="MsoNormal">
				<st1:chsdate year="2009" month="8" day="12" islunardate="False" isrocdate="False" w:st="on">
						<i style="">
								<span lang="EN-US">2009-8-12</span>
						</i>
				</st1:chsdate>
				<i style="">
						<span lang="EN-US">
								<o:p>
								</o:p>
						</span>
				</i>
		</p>
		<p class="MsoNormal">
				<i style="">
						<u>
								<span style="font-size: 14pt;" lang="EN-US">1</span>
						</u>
				</i>
				<i style="">
						<u>
								<span style="font-size: 14pt; font-family: 宋体;">．操作符重载（</span>
						</u>
				</i>
				<i style="">
						<u>
								<span style="font-size: 14pt;" lang="EN-US">operator
overloading</span>
						</u>
				</i>
				<i style="">
						<u>
								<span style="font-size: 14pt; font-family: 宋体;">）</span>
						</u>
				</i>
				<i style="">
						<u>
								<span style="font-size: 14pt;" lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</u>
				</i>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span style="font-family: 宋体;">操作符重载是一种形式的</span>
				<span lang="EN-US">C++</span>
				<span style="font-family: 宋体;">多态。操作符函数的格式如下：</span>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span lang="EN-US">operator op
(argument-list)</span>
		</p>
		<p class="MsoNormal">
				<span lang="EN-US">
						<span style="">       </span>
				</span>
				<span style="font-family: 宋体;">如：</span>
				<span lang="EN-US">operator +( const T&amp; t); t =
t1 + t2;</span>
		</p>
		<p class="MsoNormal">
				<span lang="EN-US">
						<span style="">       </span>
				</span>
				<span style="font-family: 宋体;">该函数将隐式地使用</span>
				<span lang="EN-US">t1</span>
				<span style="font-family: 宋体;">（因为它调用了方法），而显示地使用</span>
				<span lang="EN-US">t2</span>
				<span style="font-family: 宋体;">对象（因为它被作为参数传递）来计算总和。替代形式为</span>
				<span lang="EN-US"> d =
t1.operator+ (t2)</span>
				<span style="font-family: 宋体;">；</span>
				<span lang="EN-US">
						<span style="">    </span>
						<span style="">       </span>
				</span>
		</p>
		<p class="MsoNormal" style="margin-left: 18pt; text-indent: -18pt;">
				<!--[if !supportLists]-->
				<i style="">
						<span style="font-size: 12pt;" lang="EN-US">
								<span style="">1.1<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">  </span></span>
						</span>
				</i>
				<!--[endif]-->
				<i style="">
						<u>
								<span style="font-size: 12pt; font-family: 宋体;">重载的限制</span>
						</u>
				</i>
				<i style="">
						<u>
								<span style="font-size: 12pt;" lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</u>
				</i>
		</p>
		<p class="MsoNormal" style="margin-left: 21pt; text-indent: -21pt;">
				<!--[if !supportLists]-->
				<span style="font-family: Wingdings;" lang="EN-US">
						<span style="">ü<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">        
</span></span>
				</span>
				<!--[endif]-->
				<span style="font-family: 宋体;">重载后的操作符必须至少有一个操作数是用户定义的类型，这将防止用户为标准类型重载操作符。</span>
		</p>
		<p class="MsoNormal" style="margin-left: 21pt; text-indent: -21pt;">
				<!--[if !supportLists]-->
				<span style="font-family: Wingdings;" lang="EN-US">
						<span style="">ü<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">        
</span></span>
				</span>
				<!--[endif]-->
				<span style="font-family: 宋体;">使用操作符时不能违反操作符原来的句法规则。例如，不能将求模操作符（</span>
				<span lang="EN-US">%</span>
				<span style="font-family: 宋体;">）重载成一个操作数。同样，不能修改操作符的优先级。</span>
		</p>
		<p class="MsoNormal" style="margin-left: 21pt; text-indent: -21pt;">
				<!--[if !supportLists]-->
				<span style="font-family: Wingdings;" lang="EN-US">
						<span style="">ü<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">        
</span></span>
				</span>
				<!--[endif]-->
				<span style="font-family: 宋体;">不能定义新的操作符。</span>
		</p>
		<p class="MsoNormal" style="margin-left: 21pt; text-indent: -21pt;">
				<!--[if !supportLists]-->
				<span style="font-family: Wingdings;" lang="EN-US">
						<span style="">ü<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">        
</span></span>
				</span>
				<!--[endif]-->
				<span style="font-family: 宋体;">不能重载下面的操作符：</span>
		</p>
		<p class="MsoNormal" style="margin-left: 42pt; text-indent: -21pt;">
				<!--[if !supportLists]-->
				<span style="font-family: Wingdings;" lang="EN-US">
						<span style="">l<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">        
</span></span>
				</span>
				<!--[endif]-->
				<span lang="EN-US">sizeof<span style="">  </span>.<span style=""> 
</span>.*<span style="">  </span>::<span style="">  </span>?:<span style=""> 
</span>typeid<span style="">  </span>const_cast<span style="">  </span>dynamic_cast<span style=""> 
</span>reinterpret_cast<span style="">  </span>static_cast</span>
		</p>
		<p class="MsoNormal" style="margin-left: 21pt; text-indent: -21pt;">
				<!--[if !supportLists]-->
				<span style="font-family: Wingdings;" lang="EN-US">
						<span style="">ü<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">        
</span></span>
				</span>
				<!--[endif]-->
				<span style="font-family: 宋体;">以下操作符只能通过成员函数进行重载：</span>
		</p>
		<p class="MsoNormal" style="margin-left: 39pt; text-indent: -21pt;">
				<!--[if !supportLists]-->
				<span style="font-family: Wingdings;" lang="EN-US">
						<span style="">l<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">        
</span></span>
				</span>
				<!--[endif]-->
				<span lang="EN-US">=<span style="">  </span></span>
				<span style="font-family: 宋体;">（）</span>
				<span lang="EN-US">
						<span style="">  </span>[ ]<span style="">  </span>-&gt;</span>
		</p>
		<p class="MsoNormal">
				<span lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal">
				<i style="">
						<u>
								<span style="font-size: 14pt;" lang="EN-US">2</span>
						</u>
				</i>
				<i style="">
						<u>
								<span style="font-size: 14pt; font-family: 宋体;">．友元</span>
						</u>
				</i>
				<i style="">
						<u>
								<span style="font-size: 14pt;" lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</u>
				</i>
		</p>
		<p class="MsoNormal">
				<span lang="EN-US">
						<span style="">       </span>
				</span>
				<span style="font-family: 宋体;">友元为</span>
				<span lang="EN-US">C++</span>
				<span style="font-family: 宋体;">提供了另一种形式的访问权限。友元有</span>
				<span lang="EN-US">3</span>
				<span style="font-family: 宋体;">种：</span>
		</p>
		<p class="MsoNormal" style="margin-left: 39pt; text-indent: -21pt;">
				<!--[if !supportLists]-->
				<span style="font-family: Wingdings;" lang="EN-US">
						<span style="">l<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">        
</span></span>
				</span>
				<!--[endif]-->
				<span style="font-family: 宋体;">友元函数；友元类；友元成员函数</span>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span style="font-family: 宋体;">通过让函数成为类的友元，可以赋予该函数与类的成员函数相同的访问权限。<b style="">类的友元函数是非成员函数，其访问权限与成员函数相同。</b>由于只有类声明可以决定哪一个函数是友元，因此类声明仍然控制了哪些函数可以访问私有数据，所以，友元不会违背</span>
				<span lang="EN-US">OOP</span>
				<span style="font-family: 宋体;">原则。友元函数是类扩展接口的组成部分。类方法和友元是表达类接口的两种不同机制。</span>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span style="font-family: 宋体;">只有在类声明中的原型中才可以使用</span>
				<span lang="EN-US">friend</span>
				<span style="font-family: 宋体;">关键字；只有类方法才会使用类限定符，友元函数不使用类限定符。</span>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal">
				<st1:chsdate isrocdate="False" islunardate="False" day="12" month="8" year="2009" w:st="on">
						<i style="">
								<span lang="EN-US">2009-8-12</span>
						</i>
				</st1:chsdate>
				<i style="">
						<span lang="EN-US">
								<o:p>
								</o:p>
						</span>
				</i>
		</p>
		<p class="MsoNormal">
				<i style="">
						<u>
								<span style="font-size: 14pt;" lang="EN-US">3</span>
						</u>
				</i>
				<i style="">
						<u>
								<span style="font-size: 14pt; font-family: 宋体;">．类的自动转换和强制类型转换</span>
						</u>
				</i>
				<i style="">
						<u>
								<span style="font-size: 14pt;" lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</u>
				</i>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span style="font-family: 宋体;">只接受一个参数的构造函数定义了从参数类型到类类型的转换。如果使用关键字</span>
				<span lang="EN-US">explicit</span>
				<span style="font-family: 宋体;">限定了这种构造函数，则它只能使用显式转换，否则也可以用于隐式转换。</span>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span style="font-family: 宋体;">类</span>
				<span lang="EN-US">Stonewt</span>
				<span style="font-family: 宋体;">有以下构造函数：</span>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span lang="EN-US">Stonewt(double
lbs);</span>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span lang="EN-US">Stonewt(int stn,
double lbs);</span>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span style="font-family: 宋体;">则可以这样构造类型变量：</span>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span lang="EN-US">Stonewt myCat;</span>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span lang="EN-US">myCat = 19.6;</span>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span style="font-family: 宋体;">程序将使用构造函数</span>
				<span lang="EN-US">Stonewt(double)</span>
				<span style="font-family: 宋体;">来创建一个历史的</span>
				<span lang="EN-US">Stonewt</span>
				<span style="font-family: 宋体;">对象，并将</span>
				<span lang="EN-US">19.6</span>
				<span style="font-family: 宋体;">作为初始化值。随后，采用成员赋值方式将该临时对象的内容复制到</span>
				<span lang="EN-US">myCat</span>
				<span style="font-family: 宋体;">中。这一过程称为隐式转换，因为它是自动执行的，不需要显式强制类型转换。为了避免意外的类型转换，</span>
				<span lang="EN-US">C++</span>
				<span style="font-family: 宋体;">实现新增了一个关键字（</span>
				<span lang="EN-US">explicit</span>
				<span style="font-family: 宋体;">），用来关闭这种特性：</span>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span lang="EN-US">explicit
Stonewt(double lbs);</span>
		</p>
		<p class="MsoNormal">
				<i style="">
						<u>
								<span style="font-size: 12pt;" lang="EN-US">3.1 </span>
						</u>
				</i>
				<i style="">
						<u>
								<span style="font-size: 12pt; font-family: 宋体;">转换函数</span>
						</u>
				</i>
				<i style="">
						<u>
								<span style="font-size: 12pt;" lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</u>
				</i>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span style="font-family: 宋体;">构造函数只用于从某种类型到类类型的转换。要进行相反的转换，必须使用特殊的</span>
				<span lang="EN-US">C++</span>
				<span style="font-family: 宋体;">操作符函数——<b style="">转换函数</b>。转换函数形式如下：</span>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span lang="EN-US">operator
typeName( );</span>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span style="font-family: 宋体;">转换函数必须符合以下几个条件：</span>
		</p>
		<p class="MsoNormal" style="margin-left: 39pt; text-indent: -21pt;">
				<!--[if !supportLists]-->
				<span style="font-family: Wingdings;" lang="EN-US">
						<span style="">l<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">        
</span></span>
				</span>
				<!--[endif]-->
				<span style="font-family: 宋体;">转换函数必须是类方法</span>
		</p>
		<p class="MsoNormal" style="margin-left: 39pt; text-indent: -21pt;">
				<!--[if !supportLists]-->
				<span style="font-family: Wingdings;" lang="EN-US">
						<span style="">l<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">        
</span></span>
				</span>
				<!--[endif]-->
				<span style="font-family: 宋体;">转换函数不能指定返回类型</span>
		</p>
		<p class="MsoNormal" style="margin-left: 39pt; text-indent: -21pt;">
				<!--[if !supportLists]-->
				<span style="font-family: Wingdings;" lang="EN-US">
						<span style="">l<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">        
</span></span>
				</span>
				<!--[endif]-->
				<span style="font-family: 宋体;">转换函数不能有参数</span>
		</p>
		<p class="MsoNormal" style="margin-left: 18pt;">
				<span style="font-family: 宋体;">如</span>
				<span lang="EN-US"> operator double( );</span>
		</p>
		<p class="MsoNormal" style="margin-left: 18pt;">
				<span lang="EN-US">
						<span style="">
						</span>
						<span style="">  </span>operaor
int( );</span>
		</p>
		<p class="MsoNormal" style="margin-left: 18pt;">
				<br />
				<span lang="EN-US">
				</span>
		</p>
		<p class="MsoNormal" style="margin-left: 18pt;">
				<span lang="EN-US">
						<font color="#ff0000">示例代码：</font>
				</span>
		</p>
		<p class="MsoNormal" style="margin-left: 18pt;">
				<span lang="EN-US">
						<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
								<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
								<span style="color: rgb(0, 128, 0);">//</span>
								<span style="color: rgb(0, 128, 0);">mytime.h</span>
								<span style="color: rgb(0, 128, 0);">
										<br />
								</span>
								<span style="color: rgb(0, 0, 0);">#ifndef MYTIME_H_<br /></span>
								<span style="color: rgb(0, 0, 255);">#define</span>
								<span style="color: rgb(0, 0, 0);"> MYTIME_H_</span>
								<span style="color: rgb(0, 0, 0);">
										<br />
										<br />#include</span>
								<span style="color: rgb(0, 0, 0);">&lt;</span>
								<span style="color: rgb(0, 0, 0);">iostream</span>
								<span style="color: rgb(0, 0, 0);">&gt;</span>
								<span style="color: rgb(0, 0, 0);">
										<br />
										<br />
								</span>
								<span style="color: rgb(0, 0, 255);">class</span>
								<span style="color: rgb(0, 0, 0);"> Time<br />{<br /></span>
								<span style="color: rgb(0, 0, 255);">private</span>
								<span style="color: rgb(0, 0, 0);">:<br />    </span>
								<span style="color: rgb(0, 0, 255);">int</span>
								<span style="color: rgb(0, 0, 0);"> hours;<br />    </span>
								<span style="color: rgb(0, 0, 255);">int</span>
								<span style="color: rgb(0, 0, 0);"> minutes;<br /></span>
								<span style="color: rgb(0, 0, 255);">public</span>
								<span style="color: rgb(0, 0, 0);">:<br />    Time();<br />    Time(</span>
								<span style="color: rgb(0, 0, 255);">int</span>
								<span style="color: rgb(0, 0, 0);"> h, </span>
								<span style="color: rgb(0, 0, 255);">int</span>
								<span style="color: rgb(0, 0, 0);"> m </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">0</span>
								<span style="color: rgb(0, 0, 0);">);<br />    </span>
								<span style="color: rgb(0, 0, 0);">~</span>
								<span style="color: rgb(0, 0, 0);">Time();<br />    Time(</span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);"> Time</span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
								<span style="color: rgb(0, 0, 0);"> t);<br />    </span>
								<span style="color: rgb(0, 0, 255);">void</span>
								<span style="color: rgb(0, 0, 0);"> AddHr(</span>
								<span style="color: rgb(0, 0, 255);">int</span>
								<span style="color: rgb(0, 0, 0);"> h);<br />    </span>
								<span style="color: rgb(0, 0, 255);">void</span>
								<span style="color: rgb(0, 0, 0);"> AddMin(</span>
								<span style="color: rgb(0, 0, 255);">int</span>
								<span style="color: rgb(0, 0, 0);"> m);<br />    </span>
								<span style="color: rgb(0, 0, 255);">void</span>
								<span style="color: rgb(0, 0, 0);"> Reset(</span>
								<span style="color: rgb(0, 0, 255);">int</span>
								<span style="color: rgb(0, 0, 0);"> h</span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);">0</span>
								<span style="color: rgb(0, 0, 0);">, </span>
								<span style="color: rgb(0, 0, 255);">int</span>
								<span style="color: rgb(0, 0, 0);"> m </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);">0</span>
								<span style="color: rgb(0, 0, 0);">);<br />    Time </span>
								<span style="color: rgb(0, 0, 255);">operator</span>
								<span style="color: rgb(0, 0, 0);">+</span>
								<span style="color: rgb(0, 0, 0);">(</span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);"> Time</span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
								<span style="color: rgb(0, 0, 0);"> t)</span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);">;<br />    Time </span>
								<span style="color: rgb(0, 0, 255);">operator</span>
								<span style="color: rgb(0, 0, 0);">-</span>
								<span style="color: rgb(0, 0, 0);">(</span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);"> Time</span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
								<span style="color: rgb(0, 0, 0);"> t)</span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);">;<br />    Time </span>
								<span style="color: rgb(0, 0, 255);">operator</span>
								<span style="color: rgb(0, 0, 0);">*</span>
								<span style="color: rgb(0, 0, 0);">(</span>
								<span style="color: rgb(0, 0, 255);">double</span>
								<span style="color: rgb(0, 0, 0);"> n)</span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);">;<br />    </span>
								<span style="color: rgb(0, 128, 0);">//</span>
								<span style="color: rgb(0, 128, 0);">inline definition</span>
								<span style="color: rgb(0, 128, 0);">
										<br />
								</span>
								<span style="color: rgb(0, 0, 0);">    friend Time </span>
								<span style="color: rgb(0, 0, 255);">operator</span>
								<span style="color: rgb(0, 0, 0);">*</span>
								<span style="color: rgb(0, 0, 0);">(</span>
								<span style="color: rgb(0, 0, 255);">double</span>
								<span style="color: rgb(0, 0, 0);"> n, </span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);"> Time</span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
								<span style="color: rgb(0, 0, 0);"> t)<br />    {<br />        </span>
								<span style="color: rgb(0, 0, 255);">return</span>
								<span style="color: rgb(0, 0, 0);"> t </span>
								<span style="color: rgb(0, 0, 0);">*</span>
								<span style="color: rgb(0, 0, 0);"> n;<br />    }<br />    friend std::ostream</span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 255);">operator</span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);">(std::ostream</span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
								<span style="color: rgb(0, 0, 0);"> os, </span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);"> Time</span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
								<span style="color: rgb(0, 0, 0);"> t);<br />};<br /><br /><br /></span>
								<span style="color: rgb(0, 0, 255);">#endif</span>
								<span style="color: rgb(0, 0, 0);">
										<br />
										<br />
								</span>
								<span style="color: rgb(0, 128, 0);">//</span>
								<span style="color: rgb(0, 128, 0);">mytime.cpp</span>
								<span style="color: rgb(0, 128, 0);">
										<br />
								</span>
								<span style="color: rgb(0, 0, 0);">#include</span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);">mytime.h</span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);">
										<br />
										<br />Time::Time()<br />{<br />    hours </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> minutes </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">0</span>
								<span style="color: rgb(0, 0, 0);">;<br />}<br />Time::Time(</span>
								<span style="color: rgb(0, 0, 255);">int</span>
								<span style="color: rgb(0, 0, 0);"> h, </span>
								<span style="color: rgb(0, 0, 255);">int</span>
								<span style="color: rgb(0, 0, 0);"> m)<br />{<br />    hours </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> h;<br />    minutes </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> m;<br />}<br />Time::</span>
								<span style="color: rgb(0, 0, 0);">~</span>
								<span style="color: rgb(0, 0, 0);">Time()<br />{<br />    std::cout</span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);">desconstructor called. </span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> std::endl;<br />}<br />Time::Time(</span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);"> Time</span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
								<span style="color: rgb(0, 0, 0);"> t)<br />{<br />    std::cout</span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);">copy constructor called. </span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> std::endl;<br />    hours </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> t.hours;<br />    minutes </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> t.minutes;<br />}<br /></span>
								<span style="color: rgb(0, 0, 255);">void</span>
								<span style="color: rgb(0, 0, 0);"> Time::AddHr(</span>
								<span style="color: rgb(0, 0, 255);">int</span>
								<span style="color: rgb(0, 0, 0);"> h)<br />{<br />    hours </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> hours </span>
								<span style="color: rgb(0, 0, 0);">+</span>
								<span style="color: rgb(0, 0, 0);"> h;<br />}<br /></span>
								<span style="color: rgb(0, 0, 255);">void</span>
								<span style="color: rgb(0, 0, 0);"> Time::AddMin(</span>
								<span style="color: rgb(0, 0, 255);">int</span>
								<span style="color: rgb(0, 0, 0);"> m)<br />{<br />    minutes </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> minutes </span>
								<span style="color: rgb(0, 0, 0);">+</span>
								<span style="color: rgb(0, 0, 0);"> m;<br />    hours </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> hours </span>
								<span style="color: rgb(0, 0, 0);">+</span>
								<span style="color: rgb(0, 0, 0);"> minutes</span>
								<span style="color: rgb(0, 0, 0);">/</span>
								<span style="color: rgb(0, 0, 0);">60</span>
								<span style="color: rgb(0, 0, 0);">;<br />    minutes </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> minutes</span>
								<span style="color: rgb(0, 0, 0);">%</span>
								<span style="color: rgb(0, 0, 0);">60</span>
								<span style="color: rgb(0, 0, 0);">;<br />}<br /></span>
								<span style="color: rgb(0, 0, 255);">void</span>
								<span style="color: rgb(0, 0, 0);"> Time::Reset(</span>
								<span style="color: rgb(0, 0, 255);">int</span>
								<span style="color: rgb(0, 0, 0);"> h, </span>
								<span style="color: rgb(0, 0, 255);">int</span>
								<span style="color: rgb(0, 0, 0);"> m)<br />{<br />    hours </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> h;<br />    minutes </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> m;<br />}<br />Time Time::</span>
								<span style="color: rgb(0, 0, 255);">operator</span>
								<span style="color: rgb(0, 0, 0);">+</span>
								<span style="color: rgb(0, 0, 0);">(</span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);"> Time</span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
								<span style="color: rgb(0, 0, 0);"> t)</span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);">
										<br />{<br />    Time sum;<br />    sum.minutes </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> minutes </span>
								<span style="color: rgb(0, 0, 0);">+</span>
								<span style="color: rgb(0, 0, 0);"> t.minutes;<br />    sum.hours </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> hours </span>
								<span style="color: rgb(0, 0, 0);">+</span>
								<span style="color: rgb(0, 0, 0);"> t.hours </span>
								<span style="color: rgb(0, 0, 0);">+</span>
								<span style="color: rgb(0, 0, 0);"> sum.minutes </span>
								<span style="color: rgb(0, 0, 0);">/</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">60</span>
								<span style="color: rgb(0, 0, 0);">;<br />    sum.minutes </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> sum.minutes </span>
								<span style="color: rgb(0, 0, 0);">%</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">60</span>
								<span style="color: rgb(0, 0, 0);">;<br />    </span>
								<span style="color: rgb(0, 0, 255);">return</span>
								<span style="color: rgb(0, 0, 0);"> sum;<br />}<br />Time Time::</span>
								<span style="color: rgb(0, 0, 255);">operator</span>
								<span style="color: rgb(0, 0, 0);">-</span>
								<span style="color: rgb(0, 0, 0);">(</span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);"> Time</span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
								<span style="color: rgb(0, 0, 0);"> t)</span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);">
										<br />{<br />    Time sub;<br />    </span>
								<span style="color: rgb(0, 0, 255);">long</span>
								<span style="color: rgb(0, 0, 0);"> tot1,tot2;<br />    tot1 </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> t.minutes </span>
								<span style="color: rgb(0, 0, 0);">+</span>
								<span style="color: rgb(0, 0, 0);"> t.hours </span>
								<span style="color: rgb(0, 0, 0);">*</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">60</span>
								<span style="color: rgb(0, 0, 0);">;<br />    tot2 </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> minutes </span>
								<span style="color: rgb(0, 0, 0);">+</span>
								<span style="color: rgb(0, 0, 0);"> hours </span>
								<span style="color: rgb(0, 0, 0);">*</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">60</span>
								<span style="color: rgb(0, 0, 0);">;<br />    sub.minutes </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> (tot1 </span>
								<span style="color: rgb(0, 0, 0);">-</span>
								<span style="color: rgb(0, 0, 0);"> tot2) </span>
								<span style="color: rgb(0, 0, 0);">%</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">60</span>
								<span style="color: rgb(0, 0, 0);">;<br />    sub.hours </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> (tot1 </span>
								<span style="color: rgb(0, 0, 0);">-</span>
								<span style="color: rgb(0, 0, 0);"> tot2) </span>
								<span style="color: rgb(0, 0, 0);">/</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">60</span>
								<span style="color: rgb(0, 0, 0);">;<br />    </span>
								<span style="color: rgb(0, 0, 255);">return</span>
								<span style="color: rgb(0, 0, 0);"> sub;<br />}<br />Time Time::</span>
								<span style="color: rgb(0, 0, 255);">operator</span>
								<span style="color: rgb(0, 0, 0);">*</span>
								<span style="color: rgb(0, 0, 0);">(</span>
								<span style="color: rgb(0, 0, 255);">double</span>
								<span style="color: rgb(0, 0, 0);"> mult)</span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);">
										<br />{<br />    Time result;<br />    result.minutes </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> minutes </span>
								<span style="color: rgb(0, 0, 0);">*</span>
								<span style="color: rgb(0, 0, 0);"> mult;<br />    result.hours </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> hours </span>
								<span style="color: rgb(0, 0, 0);">*</span>
								<span style="color: rgb(0, 0, 0);"> mult </span>
								<span style="color: rgb(0, 0, 0);">+</span>
								<span style="color: rgb(0, 0, 0);"> result.minutes </span>
								<span style="color: rgb(0, 0, 0);">/</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">60</span>
								<span style="color: rgb(0, 0, 0);">;<br />    result.minutes </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> result.minutes </span>
								<span style="color: rgb(0, 0, 0);">%</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">60</span>
								<span style="color: rgb(0, 0, 0);">;<br />    </span>
								<span style="color: rgb(0, 0, 255);">return</span>
								<span style="color: rgb(0, 0, 0);"> result;<br />}<br />std::ostream</span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 255);">operator</span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);">(std::ostream</span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
								<span style="color: rgb(0, 0, 0);"> os, </span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);"> Time</span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
								<span style="color: rgb(0, 0, 0);"> t)<br />{<br />    os</span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> t.hours </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);"> hours,</span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> t.minutes </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);"> minutes.</span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);">;<br />    </span>
								<span style="color: rgb(0, 0, 255);">return</span>
								<span style="color: rgb(0, 0, 0);"> os;<br />}<br /><br /></span>
								<span style="color: rgb(0, 128, 0);">//</span>
								<span style="color: rgb(0, 128, 0);">usemytime.cpp</span>
								<span style="color: rgb(0, 128, 0);">
										<br />
								</span>
								<span style="color: rgb(0, 0, 0);">#include</span>
								<span style="color: rgb(0, 0, 0);">&lt;</span>
								<span style="color: rgb(0, 0, 0);">iostream</span>
								<span style="color: rgb(0, 0, 0);">&gt;</span>
								<span style="color: rgb(0, 0, 0);">
										<br />#include</span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);">mytime.h</span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);">
										<br />
										<br />
								</span>
								<span style="color: rgb(0, 0, 255);">int</span>
								<span style="color: rgb(0, 0, 0);"> main()<br />{<br />    </span>
								<span style="color: rgb(0, 0, 255);">using</span>
								<span style="color: rgb(0, 0, 0);"> std::cout;<br />    </span>
								<span style="color: rgb(0, 0, 255);">using</span>
								<span style="color: rgb(0, 0, 0);"> std::endl;<br /><br />    Time t1(</span>
								<span style="color: rgb(0, 0, 0);">3</span>
								<span style="color: rgb(0, 0, 0);">, </span>
								<span style="color: rgb(0, 0, 0);">35</span>
								<span style="color: rgb(0, 0, 0);">);<br />    Time t2(</span>
								<span style="color: rgb(0, 0, 0);">2</span>
								<span style="color: rgb(0, 0, 0);">, </span>
								<span style="color: rgb(0, 0, 0);">48</span>
								<span style="color: rgb(0, 0, 0);">);<br />    Time temp;<br />    cout </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);">t1 and t2 :\n</span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);">;<br />    cout </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> t1 </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);">; </span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> t2 </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> endl;<br />    temp </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> t1 </span>
								<span style="color: rgb(0, 0, 0);">+</span>
								<span style="color: rgb(0, 0, 0);"> t2;<br />    cout </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);">t1 + t2: </span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> temp </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> endl;<br />    temp </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> t1 </span>
								<span style="color: rgb(0, 0, 0);">*</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">1.17</span>
								<span style="color: rgb(0, 0, 0);">;<br />    cout </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);">t1 * 1.17: </span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> temp </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> endl;<br />    cout </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);">10 * t2: </span>
								<span style="color: rgb(0, 0, 0);">"</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">10</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">*</span>
								<span style="color: rgb(0, 0, 0);"> t2 </span>
								<span style="color: rgb(0, 0, 0);">&lt;&lt;</span>
								<span style="color: rgb(0, 0, 0);">endl;<br />    <br />    t2 </span>
								<span style="color: rgb(0, 0, 0);">=</span>
								<span style="color: rgb(0, 0, 0);"> Time(</span>
								<span style="color: rgb(0, 0, 0);">2</span>
								<span style="color: rgb(0, 0, 0);">,</span>
								<span style="color: rgb(0, 0, 0);">57</span>
								<span style="color: rgb(0, 0, 0);">);<br /><br />    </span>
								<span style="color: rgb(0, 0, 255);">return</span>
								<span style="color: rgb(0, 0, 0);"> </span>
								<span style="color: rgb(0, 0, 0);">0</span>
								<span style="color: rgb(0, 0, 0);">;<br />}</span>
						</div>
						<br />
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 18pt;">
				<span lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
<img src ="http://www.cppblog.com/HelloCpp/aggbug/93633.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/HelloCpp/" target="_blank">HellpCpp</a> 2009-08-17 18:58 <a href="http://www.cppblog.com/HelloCpp/articles/93633.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>对象和类（C++）</title><link>http://www.cppblog.com/HelloCpp/articles/93559.html</link><dc:creator>HellpCpp</dc:creator><author>HellpCpp</author><pubDate>Mon, 17 Aug 2009 02:11:00 GMT</pubDate><guid>http://www.cppblog.com/HelloCpp/articles/93559.html</guid><wfw:comment>http://www.cppblog.com/HelloCpp/comments/93559.html</wfw:comment><comments>http://www.cppblog.com/HelloCpp/articles/93559.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/HelloCpp/comments/commentRss/93559.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/HelloCpp/services/trackbacks/93559.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: v\:* {behavior:url(#default#VML);}o\:* {behavior:url(#default#VML);}w\:* {behavior:url(#default#VML);}.shape {behavior:url(#default#VML);}										   Normal  0    7.8 磅...&nbsp;&nbsp;<a href='http://www.cppblog.com/HelloCpp/articles/93559.html'>阅读全文</a><img src ="http://www.cppblog.com/HelloCpp/aggbug/93559.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/HelloCpp/" target="_blank">HellpCpp</a> 2009-08-17 10:11 <a href="http://www.cppblog.com/HelloCpp/articles/93559.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>