page126.html

来自「wqeqwvrw rkjqhwrjwq jkhrjqwhrwq jkhrwq」· HTML 代码 · 共 63 行

HTML
63
字号
<HTML>
<HEAD>
<TITLE>Implementation</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">
 <img src="cover75.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cover75.gif" alt="Logo" align=right>
<b>Data Structures and Algorithms 
with Object-Oriented Design Patterns in C++</b><br>
<A NAME="tex2html3464" HREF="page127.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page127.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/next_motif.gif"></A> <A NAME="tex2html3462" HREF="page125.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page125.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/up_motif.gif"></A> <A NAME="tex2html3458" HREF="page125.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page125.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/previous_motif.gif"></A> <A NAME="tex2html3466" HREF="page9.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/contents_motif.gif"></A> <A NAME="tex2html3467" HREF="page620.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page620.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/index_motif.gif"></A> <BR><HR>
<H3><A NAME="SECTION0062111000000000000000">Implementation</A></H3>
<P>
Two constructors and the destructor are defined in Program&nbsp;<A HREF="page126.html#progassoc1c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page126.html#progassoc1c"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A>.
The first constructor takes as its lone argument
a reference to an <tt>Object</tt>.
It makes its <tt>key</tt> member variable point at the specified object
and sets the <tt>value</tt> pointer to zero.
The second constructor takes two arguments--both of them a reference to an <tt>Object</tt>.
The <tt>key</tt> and <tt>value</tt> member variables are made
to point at the corresponding objects.
<P>
<P><A NAME="5555">&#160;</A><A NAME="progassoc1c">&#160;</A> <IMG WIDTH=575 HEIGHT=353 ALIGN=BOTTOM ALT="program5258" SRC="img700.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img700.gif"  ><BR>
<STRONG>Program:</STRONG> <tt>Association</tt> Class Constructor and Destructor<BR>
<P>
<P>
The destructor follows the general framework for the destructor
of a class derived from <tt>Ownership</tt>.
If the association is the owner of the contained key and value,
then those objects must be deleted by the destructor.
<P>
The remaining member functions of the <tt>Association</tt> class
are defined in Program&nbsp;<A HREF="page126.html#progassoc2c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page126.html#progassoc2c"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A>.
The first two, <tt>Key</tt> and <tt>Value</tt>, are member variable accessors.
The former returns a reference to the key object
obtained by dereferencing the <tt>key</tt> member variable;
the latter, a reference to the value object
obtained by dereferencing the <tt>value</tt> member variable.
<P>
<P><A NAME="5558">&#160;</A><A NAME="progassoc2c">&#160;</A> <IMG WIDTH=575 HEIGHT=486 ALIGN=BOTTOM ALT="program5275" SRC="img701.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img701.gif"  ><BR>
<STRONG>Program:</STRONG> <tt>Association</tt> Class Member Functions<BR>
<P>
<P>
The <tt>CompareTo</tt> function is one place where
an association distinguishes between the key and the value.
The <tt>CompareTo</tt> function only operates on the key.
The <tt>CompareTo</tt> function takes as its lone argument
a <tt>const</tt> reference to <tt>Object</tt>.
It uses the <tt>dynamiccast</tt><A NAME=5295>&#160;</A>
operator to convert the argument to an <tt>Association</tt>.
The result of the comparison is based solely
on the keys of the objects--the values have no r&#244;le in the comparison.
<P>
Finally, the purpose of the <tt>Put</tt> member function
is to print out a representation of the association.
The implementation is trivial and needs no further explanation.
<P>
<HR><A NAME="tex2html3464" HREF="page127.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page127.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/next_motif.gif"></A> <A NAME="tex2html3462" HREF="page125.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page125.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/up_motif.gif"></A> <A NAME="tex2html3458" HREF="page125.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page125.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/previous_motif.gif"></A> <A NAME="tex2html3466" HREF="page9.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/contents_motif.gif"></A> <A NAME="tex2html3467" HREF="page620.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page620.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/index_motif.gif"></A> <P><ADDRESS>
<img src="bruno.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/bruno.gif" alt="Bruno" align=right>
<a href="javascript:if(confirm('http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html'" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html">Copyright &#169; 1997</a> by <a href="javascript:if(confirm('http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html'" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html">Bruno R. Preiss, P.Eng.</a>  All rights reserved.

</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?