亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ch15.htm

?? good book for learning c++ standard language
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
321:    
322:            if (!choice)
323:               break;
324:    
325:            cout << "New PartNumber?: ";
326:            cin >>  PartNumber;
327:    
328:            if (choice == 1)
329:            {
330:               cout << "Model Year?: ";
331:               cin >> value;
332:               pPart = new CarPart(value,PartNumber);
333:            }
334:            else
335:            {
336:               cout << "Engine Number?: ";
337:               cin >> value;
338:               pPart = new AirPlanePart(value,PartNumber);
339:            }
340:            pc.Insert(pPart);
341:         }
342:         pc.ShowAll();
343:        return 0;
<TT>344: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: (0)Quit (1)Car (2)Plane:  1
New PartNumber?: 1234
Model Year?: 94
(0)Quit (1)Car (2)Plane:  1
New PartNumber?: 4434
Model Year?: 93
(0)Quit (1)Car (2)Plane:  1
New PartNumber?: 1234
Model Year?: 94
1234 was the first entry. Rejected!
(0)Quit (1)Car (2)Plane:  1
New PartNumber?: 2345
Model Year?: 93
(0)Quit (1)Car (2)Plane:  0

Part Number: 1234
Model Year: 94

Part Number: 2345
Model Year: 93

Part Number: 4434
Model Year: 93
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>Listing 15.7 reproduces the
interface to the <TT>Part</TT>, <TT>PartNode</TT>, and <TT>PartList</TT> classes
from Week 2 in Review, but to save room it does not reproduce the implementation
of their methods.</P>
<P>A new class, <TT>PartsCatalog</TT>, is declared on lines 260-270. <TT>PartsCatalog</TT>
has a <TT>PartsList</TT> as its data member, to which it delegates list management.
Another way to say this is that the <TT>PartsCatalog</TT> is implemented in terms
of this <TT>PartsList</TT>.</P>
<P>Note that clients of the <TT>PartsCatalog</TT> do not have access to the <TT>PartsList</TT>
directly. The interface is through the <TT>PartsCatalog</TT>, and as such the behavior
of the <TT>PartsList</TT> is dramatically changed. For example, the <TT>PartsCatalog::Insert()</TT>
method does not allow duplicate entries into the <TT>PartsList</TT>.</P>
<P>The implementation of <TT>PartsCatalog::Insert()</TT> starts on line 272. The
<TT>Part</TT> that is passed in as a parameter is asked for the value of its <TT>itsPartNumber</TT>
member variable. This value is fed to the <TT>PartsList</TT>'s <TT>Find()</TT> method,
and if no match is found the number is inserted; otherwise an informative error message
is printed.</P>
<P>Note that <TT>PartsCatalog</TT> does the actual insert by calling <TT>Insert()</TT>
on its member variable, <TT>pl</TT>, which is a <TT>PartsList</TT>. The mechanics
of the actual insertion and the maintenance of the linked list, as well as searching
and retrieving from the linked list, are maintained in the contained <TT>PartsList</TT>
member of <TT>PartsCatalog</TT>. There is no reason for <TT>PartsCatalog</TT> to
reproduce this code; it can take full advantage of the well-defined interface.</P>
<P>This is the essence of reusability within C++: <TT>PartsCatalog</TT> can reuse
the <TT>PartsList</TT> code, and the designer of <TT>PartsCatalog</TT> is free to
ignore the implementation details of <TT>PartsList</TT>. The interface to <TT>PartsList</TT>
(that is, the class declaration) provides all the information needed by the designer
of the <TT>PartsCatalog</TT> class.
<H3 ALIGN="CENTER"><A NAME="Heading20"></A><FONT COLOR="#000077">Private Inheritance</FONT></H3>
<P>If <TT>PartsCatalog</TT> needed access to the protected members of <TT>LinkedList</TT>
(in this case there are none), or needed to override any of the <TT>LinkedList</TT>
methods, then <TT>PartsCatalog</TT> would be forced to inherit from <TT>PartsList</TT>.</P>
<P>Since a <TT>PartsCatalog</TT> is not a <TT>PartsList</TT> object, and since you
don't want to expose the entire set of functionality of <TT>PartsList</TT> to clients
of <TT>PartsCatalog</TT>, you need to use private inheritance.</P>
<P>The first thing to know about private inheritance is that all of the base member
variables and functions are treated as if they were declared to be private, regardless
of their actual access level in the base. Thus, to any function that is not a member
function of <TT>PartsCatalog</TT>, every function inherited from <TT>PartsList</TT>
is inaccessible. This is critical: private inheritance does not involve inheriting
interface, just implementation.</P>
<P>To clients of the <TT>PartsCatalog</TT> class, the <TT>PartsList</TT> class is
invisible. None of its interface is available: you can't call any of its methods.
You can call <TT>PartsCatalog</TT> methods, however, and they can access all of <TT>LinkedLists</TT>,
because they are derived from <TT>LinkedLists</TT>.</P>
<P>The important thing here is that the <TT>PartsCatalog</TT> isn't a <TT>PartsList</TT>,
as would have been implied by public inheritance. It is implemented in terms of a
<TT>PartsList</TT>, just as would have been the case with containment. The private
inheritance is just a convenience.</P>
<P>Listing 15.6 demonstrates the use of private inheritance by rewriting the <TT>PartsCatalog</TT>
class as privately derived from <TT>PartsList</TT>.


<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>To compile this program, replace
	lines 260-344 of Listing 15.5 with Listing 15.6 and recompile. 
<HR>


</BLOCKQUOTE>

<P><A NAME="Heading21"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 15.6. Private
inheritance.</B></FONT>
<PRE><FONT COLOR="#0066FF">1:  //listing 15.6 demonstrates private inheritance
2:
3:  //rewrites PartsCatalog from listing 15.5
4:
5:  //see attached notes on compiling
6:
7:     class PartsCatalog : private PartsList
8:     {
9:     public:
10:       void Insert(Part *);
11:       ULONG Exists(ULONG PartNumber);
12:       Part * Get(int PartNumber);
13:       operator+(const PartsCatalog &amp;);
14:       void ShowAll() { Iterate(Part::Display); }
15:    private:
16:    };
17:
18:    void PartsCatalog::Insert(Part * newPart)
19:    {
20:       ULONG partNumber =  newPart-&gt;GetPartNumber();
21:       ULONG offset;
22:
23:       if (!Find(offset, partNumber))
24:          PartsList::Insert(newPart);
25:       else
26:       {
27:          cout &lt;&lt; partNumber &lt;&lt; &quot; was the &quot;;
28:          switch (offset)
29:          {
30:             case 0:  cout &lt;&lt; &quot;first &quot;; break;
31:             case 1:  cout &lt;&lt; &quot;second &quot;; break;
32:             case 2:  cout &lt;&lt; &quot;third &quot;; break;
33:             default: cout &lt;&lt; offset+1 &lt;&lt; &quot;th &quot;;
34:          }
35:          cout &lt;&lt; &quot;entry. Rejected!\n&quot;;
36:       }
37:    }
38:
39:    ULONG PartsCatalog::Exists(ULONG PartNumber)
40:    {
41:       ULONG offset;
42:       Find(offset,PartNumber);
43:       return offset;
44:    }
45:
46:    Part * PartsCatalog::Get(int PartNumber)
47:    {
48:       ULONG offset;
49:       return (Find(offset, PartNumber));
50:
51:    }
52:
53:    int main()
54:    {
55:       PartsCatalog pc;
56:       Part * pPart = 0;
57:       ULONG PartNumber;
58:       USHORT value;
59:       ULONG choice;
60:
61:       while (1)
62:       {
63:          cout &lt;&lt; &quot;(0)Quit (1)Car (2)Plane: &quot;;
64:          cin &gt;&gt; choice;
65:
66:          if (!choice)
67:             break;
68:
69:          cout &lt;&lt; &quot;New PartNumber?: &quot;;
70:          cin &gt;&gt;  PartNumber;
71:
72:          if (choice == 1)
73:          {
74:             cout &lt;&lt; &quot;Model Year?: &quot;;
75:             cin &gt;&gt; value;
76:             pPart = new CarPart(value,PartNumber);
77:          }
78:          else
79:          {
80:             cout &lt;&lt; &quot;Engine Number?: &quot;;
81:             cin &gt;&gt; value;
82:             pPart = new AirPlanePart(value,PartNumber);
83:          }
84:          pc.Insert(pPart);
85:       }
86:       pc.ShowAll();
87:     return 0;
<TT>88: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: (0)Quit (1)Car (2)Plane:  1
New PartNumber?: 1234
Model Year?: 94
(0)Quit (1)Car (2)Plane:  1
New PartNumber?: 4434
Model Year?: 93
(0)Quit (1)Car (2)Plane:  1
New PartNumber?: 1234
Model Year?: 94
1234 was the first entry. Rejected!
(0)Quit (1)Car (2)Plane:  1
New PartNumber?: 2345
Model Year?: 93
(0)Quit (1)Car (2)Plane:  0

Part Number: 1234
Model Year: 94

Part Number: 2345
Model Year: 93

Part Number: 4434
Model Year: 93
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>Listing 15.6 shows only the
changed interface to <TT>PartsCatalog</TT> and the rewritten driver program. The
interfaces to the other classes are unchanged from Listing 15.5.</P>
<P>On line 7 of Listing 15.6, <TT>PartsCatalog</TT> is declared to derive privately
from <TT>PartsList</TT>. The interface to <TT>PartsCatalog</TT> doesn't change from
Listing 15.5, though of course it no longer needs an object of type <TT>PartsList</TT>
as member data.</P>
<P>The <TT>PartsCatalog</TT> <TT>ShowAll()</TT> function calls <TT>PartsList</TT>
<TT>Iterate()</TT> with the appropriate pointer to member function of class <TT>Part</TT>.
<TT>ShowAll()</TT> acts as a public interface to <TT>Iterate()</TT>, providing the
correct information but preventing client classes from calling <TT>Iterate()</TT>
dir-ectly. Although <TT>PartsList</TT> might allow other functions to be passed to
<TT>Iterate()</TT>, <TT>PartsCatalog</TT> does not.</P>
<P>The <TT>Insert()</TT> function has changed as well. Note, on line 23, that <TT>Find()</TT>
is now called directly, because it is inherited from the base class. The call on
line 24 to <TT>Insert()</TT> must be fully qualified, of course, or it would endlessly
recurse into itself.</P>
<P>In short, when methods of <TT>PartsCatalog</TT> want to call <TT>PartsList</TT>
methods, they may do so directly. The only exception is when <TT>PartsCatalog</TT>
has overridden the method and the <TT>PartsList</TT> version is needed, in which
case the function name must be qualified fully.</P>
<P>Private inheritance allows the <TT>PartsCatalog</TT> to inherit what it can use,
but still provide mediated access to <TT>Insert</TT> and other methods to which client
classes should not have direct access.


<BLOCKQUOTE>
	<P>
<HR>
<B>DO </B>inherit publicly when the derived object is a kind of the base class. <B>DO</B>
	use containment when you want to delegate functionality to another class, but you
	don't need access to its protected members.<B> DO</B> use private inheritance when
	you need to implement one class in terms of another, and you need access to the base
	class's protected members. <B>DON'T </B>use private inheritance when you need to
	use more than one of the base class. You must use containment. For example, if <TT>PartsCatalog</TT>
	needed two <TT>PartsLists</TT>, you could not have used private inheritance. <B>DON'T</B>
	use public inheritance when members of the base class should not be available to
	clients of the derived class. 
<HR>


</BLOCKQUOTE>

<H3 ALIGN="CENTER"><A NAME="Heading24"></A><FONT COLOR="#000077">Friend Classes</FONT></H3>
<P>Sometimes you will create classes together, as a set. For example, <TT>PartNode</TT>
and <TT>PartsList</TT> were tightly coupled, and it would have been convenient if
<TT>PartsList</TT> could have read <TT>PartNode</TT>'s <TT>Part</TT> pointer, <TT>itsPart</TT>,
directly.</P>
<P>You wouldn't want to make <TT>itsPart</TT> public, or even protected, because
this is an implementation detail of <TT>PartNode</TT> and you want to keep it private.
You do want to expose it to <TT>PartsList</TT>, however.</P>
<P>If you want to expose your private member data or functions to another class,
you must declare that class to be a friend. This extends the interface of your class
to include the friend class.</P>
<P>Once <TT>PartsNode</TT> declares <TT>PartsList</TT> to be a friend, all of <TT>PartsNode</TT>'s
member data and functions are public as far as <TT>PartsList</TT> is concerned.</P>
<P>It is important to note that friendship cannot be transferred. Just because you
are my friend and Joe is your friend doesn't mean Joe is my friend. Friendship is
not inherited either. Again, just because you are my friend and I'm willing to share
my secrets with you doesn't mean I'm willing to share my secrets with your children.</P>
<P>Finally, friendship is not commutative. Assigning <TT>Class One</TT> to be a friend
of <TT>Class Two</TT> does not make <TT>Class Two</TT> a friend of <TT>Class One</TT>.
Just because you are willing to tell me your secrets doesn't mean I am willing to
tell you mine.</P>
<P>Listing 15.7 illustrates friendship by rewriting the example from Listing 15.6,
making <TT>PartsList</TT> a friend of <TT>PartNode</TT>. Note that this does not
make <TT>PartNode</TT> a friend of <TT>PartsList</TT>.</P>

<P><A NAME="Heading25"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 15.7. Friend
class illustrated.</B></FONT>
<PRE><FONT COLOR="#0066FF">0:      #include &lt;iostream.h&gt;
1:    
2:      typedef unsigned long ULONG;
3:      typedef unsigned short USHORT;
4:    
5:    
6:      // **************** Part ************
7:    
8:      // Abstract base class of parts
9:      class Part
10:       {
11:       public:
12:          Part():itsPartNumber(1) {}
13:          Part(ULONG PartNumber):
14:              itsPartNumber(PartNumber){}
15:          virtual ~Part(){}
16:          ULONG GetPartNumber() const 
17:              { return itsPartNumber; }
18:          virtual void Display() const =0; 
19:       private:
20:          ULONG itsPartNumber;
21:       };
22:     
23:       // implementation of pure virtual function so that
24:       // derived classes can chain up
25:       void Part::Display() const
26:       {
27:           cout &lt;&lt; &quot;\nPart Number: &quot;;
28:           cout &lt;&lt; itsPartNumber &lt;&lt; endl;
29:       }
30:     
31:       // **************** Car Part ************
32:     
33:       class CarPart : public Part
34:       {
35:       public:
36:          CarPart():itsModelYear(94){}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文字幕精品一区二区精品绿巨人| 国产精品丝袜一区| 亚瑟在线精品视频| 欧美三级午夜理伦三级中视频| 一区二区三区欧美在线观看| 91极品视觉盛宴| 天天av天天翘天天综合网色鬼国产| 色综合色狠狠天天综合色| 亚洲一区二区av电影| 91精品国产色综合久久不卡蜜臀 | 亚洲精品高清在线| 精品视频999| 精品在线播放免费| 久久一区二区视频| 91麻豆免费看片| 日韩经典一区二区| 久久久久99精品国产片| 日本韩国欧美三级| 免费高清成人在线| 亚洲欧洲日产国产综合网| 欧美性大战久久久| 国产在线精品一区二区不卡了| 国产精品青草久久| 欧美一区二区国产| 不卡欧美aaaaa| 蜜桃精品视频在线| 国产精品卡一卡二卡三| 91精品久久久久久久久99蜜臂| 韩国视频一区二区| 亚洲欧美另类久久久精品| 日韩欧美一区电影| 99久久99精品久久久久久| 日本最新不卡在线| 一区二区三区欧美久久| 久久综合久久综合久久| 在线观看亚洲精品视频| 国产馆精品极品| 日韩激情av在线| 亚洲日本va午夜在线影院| 欧美大片在线观看一区二区| 一本久久a久久精品亚洲| 欧美优质美女网站| 国产一二三精品| 亚洲第一福利视频在线| 自拍偷拍亚洲综合| 国产女人水真多18毛片18精品视频| 欧美日韩黄视频| av午夜精品一区二区三区| 久久99国产精品麻豆| 亚洲成va人在线观看| 国产精品不卡视频| 久久久精品影视| 欧美变态tickle挠乳网站| 欧美日韩在线不卡| 在线免费不卡电影| 97精品电影院| 成人免费高清在线观看| 亚洲日本护士毛茸茸| 欧美一区二区在线不卡| 欧美亚洲国产怡红院影院| 国产成人精品影院| 激情综合色综合久久| 日韩精品欧美精品| 亚洲国产精品久久人人爱| 亚洲激情五月婷婷| 国产精品精品国产色婷婷| 国产亚洲精品7777| av亚洲产国偷v产偷v自拍| 日韩av一级电影| 亚洲成av人片在线观看| 一区二区三区在线视频免费观看 | 久久亚洲欧美国产精品乐播| 欧美一区二区三区视频在线| 欧美乱妇23p| 欧美高清视频不卡网| 欧美欧美欧美欧美首页| 91麻豆精品久久久久蜜臀| 欧美剧情电影在线观看完整版免费励志电影| 成人黄色在线视频| av一区二区三区黑人| 99热这里都是精品| 成人av电影在线| 91在线国产福利| 91蝌蚪porny成人天涯| 色综合中文字幕| 欧美一a一片一级一片| 欧美日韩国产综合视频在线观看 | 欧美在线视频日韩| 欧美日韩国产影片| 日韩欧美亚洲另类制服综合在线| 91精品国产色综合久久不卡电影| 欧美精品777| 久久久久99精品一区| 国产精品久久久久久久久久免费看| 亚洲特级片在线| 亚洲国产成人tv| 九九在线精品视频| 成人免费毛片app| 在线免费视频一区二区| 3d动漫精品啪啪| 久久蜜桃一区二区| 亚洲欧美日韩精品久久久久| 亚洲大尺度视频在线观看| 久久99久久精品欧美| 国产成人精品三级麻豆| 在线一区二区视频| 久久综合久久久久88| 亚洲美女视频一区| 丝袜亚洲另类欧美综合| 国产精品一卡二| 日本精品一区二区三区四区的功能| 欧美高清视频一二三区| 亚洲国产精品av| 日日摸夜夜添夜夜添精品视频 | 99视频超级精品| ...中文天堂在线一区| 午夜精品福利在线| 国产精品 欧美精品| 欧美日本在线视频| 国产精品成人免费精品自在线观看| 亚洲va欧美va天堂v国产综合| 久久 天天综合| 欧美日韩专区在线| 国产精品大尺度| 男人的天堂亚洲一区| 91久久精品一区二区二区| 欧美不卡在线视频| 亚洲一线二线三线视频| 国产成a人亚洲精| 欧美电影在线免费观看| 亚洲特黄一级片| 国产一区二区电影| 欧美精品久久久久久久多人混战 | 国产一区二区三区四区五区美女| 色先锋资源久久综合| 久久在线免费观看| 午夜久久久久久| 97精品久久久午夜一区二区三区 | 日韩高清一区二区| 国产99久久久精品| 日韩一区二区三区在线观看| 亚洲欧美日韩一区二区三区在线观看| 韩国一区二区三区| 91精品国产91久久久久久最新毛片 | 欧美嫩在线观看| 综合久久久久久| 国产成人在线色| wwwwxxxxx欧美| 老司机精品视频导航| 正在播放一区二区| 亚洲一二三专区| 在线视频国产一区| 亚洲激情五月婷婷| 色综合久久久久综合体| 亚洲人妖av一区二区| 成人免费看视频| 欧美国产日韩a欧美在线观看| 紧缚奴在线一区二区三区| 欧美一区二区美女| 26uuu久久综合| 亚洲视频一区在线观看| 韩国女主播一区| 欧美va日韩va| 美国av一区二区| 欧美一区二区高清| 美女www一区二区| 精品av综合导航| 麻豆精品新av中文字幕| 欧美成人官网二区| 国产一区二区三区蝌蚪| 久久久亚洲午夜电影| 国产白丝网站精品污在线入口| 久久久午夜精品| 成人一区二区三区视频在线观看| 中文字幕 久热精品 视频在线| 成人性生交大片免费看视频在线| 国产精品美女一区二区在线观看| 99久久精品情趣| 亚洲欧洲另类国产综合| 91一区二区在线| 亚洲成人免费视| 6080国产精品一区二区| 蜜桃久久av一区| 久久午夜色播影院免费高清| 成人一二三区视频| 一区二区三区四区蜜桃| 欧美日韩精品高清| 精品在线一区二区| 国产精品久久久久国产精品日日| 99精品1区2区| 午夜成人免费视频| 精品精品欲导航| 波多野结衣91| 午夜成人免费视频| 久久女同精品一区二区| 91免费看`日韩一区二区| 视频一区视频二区中文| 久久精品视频一区二区| 精品三级在线观看| 岛国精品在线播放|