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

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? 020.htm

?? 21天內(nèi)快速掌握c++語(yǔ)言
?? HTM
?? 第 1 頁(yè) / 共 5 頁(yè)
字號(hào):
19:
20:          // friend function
21:         friend ostream& operator<< (ostream&, const Array&);
22:
23:          class xBoundary {};  // define the exception class
24:       private:
25:          int *pType;
26:          int  itsSize;
27:       };
28:
29:
30:       Array::Array(int size):
31:       itsSize(size)
32:       {
33:          pType = new int[size];
34:          for (int i = 0; i<size; i++)
35:            pType[i] = 0;
36:       }
37:
38:
39:       Array& Array::operator=(const Array &rhs)
40:       {
41:          if (this == &rhs)
42:             return *this;
43:          delete [] pType;
44:          itsSize = rhs.GetitsSize();
45:          pType = new int[itsSize];
46:          for (int i = 0; i<itsSize; i++)
47:             pType[i] = rhs[i];
48:          return *this;
49:       }
50:
51:       Array::Array(const Array &rhs)
52:       {
53:          itsSize = rhs.GetitsSize();
54:          pType = new int[itsSize];
55:          for (int i = 0; i<itsSize; i++)
56:             pType[i] = rhs[i];
57:       }
58:
59:
60:       int& Array::operator[](int offSet)
61:       {
62:          int size = GetitsSize();
63:          if (offSet >= 0 && offSet < GetitsSize())
64:             return pType[offSet];
65:          throw xBoundary();
66:          return pType[0]; // appease MSC
67:       }
68:
69:
70:       const int& Array::operator[](int offSet) const
71:       {
72:          int mysize = GetitsSize();
73:          if (offSet >= 0 && offSet < GetitsSize())
74:             return pType[offSet];
75:          throw xBoundary();
76:          return pType[0]; // appease MSC
77:       }
78:
79:       ostream& operator<< (ostream& output, const Array& theArray)
80:       {
81:          for (int i = 0; i<theArray.GetitsSize(); i++)
82:             output << "[" << i << "] " << theArray[i] << endl;
83:          return output;
100:       }
85:
86:       int main()
87:       {
88:          Array intArray(20);
89:          try
90:          {
91:             for (int j = 0; j< 100; j++)
92:             {
93:                intArray[j] = j;
94:                cout << "intArray[" << j << "] okay..." << endl;
95:             }
96:          }
97:          catch (Array::xBoundary)
98:          {
99:             cout << "Unable to process your input!\n";
100:          }
101:          cout << "Done.\n";
102:         return 0;
<TT>103: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: intArray[0] okay...
intArray[1] okay...
intArray[2] okay...
intArray[3] okay...
intArray[4] okay...
intArray[5] okay...
intArray[6] okay...
intArray[7] okay...
intArray[8] okay...
intArray[9] okay...
intArray[10] okay...
intArray[11] okay...
intArray[12] okay...
intArray[13] okay...
intArray[14] okay...
intArray[15] okay...
intArray[16] okay...
intArray[17] okay...
intArray[18] okay...
intArray[19] okay...
Unable to process your input!
Done.
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>Listing 20.1 presents a somewhat
stripped-down <TT>Array</TT> class, based on the template developed on Day 19, &quot;Templates.&quot;
On line 23, a new class is contained within the declaration of the boundary.<BR>
<BR>
This new class is not in any way distinguished as an exception class. It is just
a class like any other. This particular class is incredibly simple: It has no data
and no methods. Nonetheless, it is a valid class in every way.</P>
<P>In fact, it is incorrect to say it has no methods, because the compiler automatically
assigns it a default constructor, destructor, copy constructor, and the copy operator
(operator equals); so it actually has four class functions, but no data.</P>
<P>Note that declaring it from within <TT>Array</TT> serves only to couple the two
classes together. As discussed on Day 15, &quot;Advanced Inheritance,&quot; <TT>Array</TT>
has no special access to <TT>xBoundary</TT>, nor does <TT>xBoundary</TT> have preferential
access to the members of <TT>Array</TT>.</P>
<P>On lines 60-66 and 69-75, the offset operators are modified to examine the offset
requested and, if it is out of range, to throw the <TT>xBoundary</TT> class as an
exception. The parentheses are required to distinguish between this call to the <TT>xBoundary</TT>
constructor and the use of an enumerated constant. Note that Microsoft requires that
you provide a <TT>return</TT> statement to match the declaration (in this case, returning
an integer reference), even though if an exception is thrown on line 65 the code
will never reach line 66. This is a compiler bug, proving only that even Microsoft
finds this stuff difficult and confusing!</P>
<P>On line 89, the keyword <TT>try</TT> begins a <TT>try</TT> block that ends on
line 96. Within that <TT>try</TT> block, 100 integers are added to the array that
was declared on line 88.</P>
<P>On line 97, the <TT>catch</TT> block to catch <TT>xBoundary</TT> exceptions is
declared.</P>
<P>In the driver program on lines 86-103, a <TT>try</TT> block is created in which
each member of the array is initialized. When <TT>j</TT> (line 91) is incremented
to 20, the member at offset 20 is accessed. This causes the test on line 63 to fail,
and <TT>operator[]</TT> raises an <TT>xBoundary</TT> exception on line 65.</P>
<P>Program control switches to the <TT>catch</TT> block on line 97, and the exception
is caught or handled by the <TT>catch</TT> on the same line, which prints an error
message. Program flow drops through to the end of the <TT>catch</TT> block on line
100.
<H3 ALIGN="CENTER"><A NAME="Heading9"></A><FONT COLOR="#000077">try Blocks</FONT></H3>
<P>A <TT>try</TT> block is a set of statements that begins with the word <TT>try</TT>,
is followed by an opening brace, and ends with a closing brace. Example:</P>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">try
{
Function();
};
</FONT></PRE>
<H3 ALIGN="CENTER"><A NAME="Heading10"></A><FONT COLOR="#000077">catch Blocks</FONT></H3>
<P>A <TT>catch</TT> block is a series of statements, each of which begins with the
word <TT>catch</TT>, followed by an exception type in parentheses, followed by an
opening brace, and ending with a closing brace. Example:</P>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">try
{
Function();
};
catch (OutOfMemory)
{
// take action
}
</FONT></PRE>
<H3 ALIGN="CENTER"><A NAME="Heading11"></A><FONT COLOR="#000077">Using try Blocks
and catch Blocks</FONT></H3>
<P>Figuring out where to put your <TT>try</TT> blocks is non-trivial: It is not always
obvious which actions might raise an exception. The next question is where to catch
the exception. It may be that you'll want to throw all memory exceptions where the
memory is allocated, but you'll want to catch the exceptions high in the program,
where you deal with the user interface.</P>
<P>When trying to determine <TT>try</TT> block locations, look to where you allocate
memory or use resources. Other things to look for are out-of-bounds errors, illegal
input, and so forth.
<H4 ALIGN="CENTER"><A NAME="Heading12"></A><FONT COLOR="#000077">Catching Exceptions</FONT></H4>
<P>Here's how it works: when an exception is thrown, the call stack is examined.
The call stack is the list of function calls created when one part of the program
invokes another function.</P>
<P>The call stack tracks the execution path. If <TT>main()</TT> calls the function
<TT>Animal::GetFavoriteFood()</TT>, and <TT>GetFavoriteFood()</TT> calls <TT>Animal::LookupPreferences()</TT>,
which in turn calls <TT>fstream::operator&gt;&gt;()</TT>, all these are on the call
stack. A recursive function might be on the call stack many times.</P>
<P>The exception is passed up the call stack to each enclosing block. As the stack
is unwound, the destructors for local objects on the stack are invoked, and the objects
are destroyed.</P>
<P>After each <TT>try</TT> block there is one or more <TT>catch</TT> statements.
If the exception matches one of the <TT>catch</TT> statements, it is considered to
be handled by having that statement execute. If it doesn't match any, the unwinding
of the stack continues.</P>
<P>If the exception reaches all the way to the beginning of the program (<TT>main()</TT>)
and is still not caught, a built-in handler is called that terminates the program.</P>
<P>It is important to note that the exception unwinding of the stack is a one-way
street. As it progresses, the stack is unwound and objects on the stack are destroyed.
There is no going back: Once the exception is handled, the program continues after
the <TT>try</TT> block of the <TT>catch</TT> statement that handled the exception.</P>
<P>Thus, in Listing 20.1, execution will continue on line 101, the first line after
the <TT>try</TT> block of the <TT>catch</TT> statement that handled the <TT>xBoundary</TT>
exception. Remember that when an exception is raised, program flow continues after
the <TT>catch</TT> block, not after the point where the exception was thrown.
<H4 ALIGN="CENTER"><A NAME="Heading13"></A><FONT COLOR="#000077">More Than One catch
Specification</FONT></H4>
<P>It is possible for more than one condition to cause an exception. In this case,
the <TT>catch</TT> statements can be lined up one after another, much like the conditions
in a <TT>switch</TT> statement. The equivalent to the <TT>default</TT> statement
is the &quot;catch everything&quot; statement, indicated by <TT>catch(...)</TT>.
Listing 20.2 illustrates multiple exception conditions.</P>
<BR>
<P><A NAME="Heading14"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 20.2. Multiple
exceptions.</B></FONT>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">0:     #include &lt;iostream.h&gt;
1:
2:     const int DefaultSize = 10;
3:
4:     class Array
5:     {
6:     public:
7:        // constructors
8:        Array(int itsSize = DefaultSize);
9:        Array(const Array &amp;rhs);
10:        ~Array() { delete [] pType;}
11:
12:        // operators
13:        Array&amp; operator=(const Array&amp;);
14:        int&amp; operator[](int offSet);
15:        const int&amp; operator[](int offSet) const;
16:
17:        // accessors
18:        int GetitsSize() const { return itsSize; }
19:
20:        // friend function
21:       friend ostream&amp; operator&lt;&lt; (ostream&amp;, const Array&amp;);
22:
23:      // define the exception classes
24:        class xBoundary {};
25:        class xTooBig {};
26:        class xTooSmall{};
27:        class xZero {};
28:        class xNegative {};
29:     private:
30:        int *pType;
31:        int  itsSize;
32:     };
33:
34:        int&amp; Array::operator[](int offSet)
35:        {
36:             int size = GetitsSize();
37:             if (offSet &gt;= 0 &amp;&amp; offSet &lt; GetitsSize())
38:                return pType[offSet];
39:             throw xBoundary();
40:             return pType[0];  // appease MFC
41:        }
42:
43:
44:        const int&amp; Array::operator[](int offSet) const
45:        {
46:             int mysize = GetitsSize();
47:             if (offSet &gt;= 0 &amp;&amp; offSet &lt; GetitsSize())
48:                return pType[offSet];
49:             throw xBoundary();
50:             return pType[0];
51:             return pType[0];  // appease MFC
52:        }
53:
54:
55:     Array::Array(int size):
56:     itsSize(size)
57:     {
58:        if (size == 0)
59:           throw xZero();
60:        if (size &lt; 10)
61:           throw xTooSmall();
62:        if (size &gt; 30000)
63:           throw xTooBig();
64:        if (size &lt; 1)
65:           throw xNegative();
66:
67:        pType = new int[size];
68:        for (int i = 0; i&lt;size; i++)
69:          pType[i] = 0;
70:     }
71:
72:
73:
74:     int main()
75:     {
76:
77:        try
78:        {
79:           Array intArray(0);
80:           for (int j = 0; j&lt; 100; j++)
81:           {
82:              intArray[j] = j;
83:              cout &lt;&lt; &quot;intArray[&quot; &lt;&lt; j &lt;&lt; &quot;] okay...\n&quot;;
100:           }
85:        }
86:        catch (Array::xBoundary)

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91美女片黄在线| 国产精品18久久久久久vr| 成人黄色777网| 91精品欧美福利在线观看| 中文字幕一区在线观看视频| 久久99精品国产麻豆婷婷| 欧洲亚洲国产日韩| 欧美激情在线一区二区三区| 日韩av电影免费观看高清完整版在线观看 | 色综合夜色一区| 亚洲美女屁股眼交| 国产酒店精品激情| 在线综合+亚洲+欧美中文字幕| 国产精品久久久久久久午夜片 | 亚洲天堂2016| 国产精品一区二区久激情瑜伽| 91精品国产综合久久久久久久| 亚洲免费在线观看视频| 风间由美性色一区二区三区| 精品少妇一区二区三区免费观看| 亚洲第一搞黄网站| 91豆麻精品91久久久久久| 中文字幕在线免费不卡| 国产jizzjizz一区二区| 2020国产精品自拍| 狠狠色2019综合网| 精品久久久影院| 久久国产综合精品| 日韩一区二区三区在线| 日韩电影一区二区三区四区| 欧美图片一区二区三区| 一级特黄大欧美久久久| 色av综合在线| 一区二区三区丝袜| 日本韩国精品在线| 亚洲精品乱码久久久久久日本蜜臀| 91在线观看高清| 亚洲日本在线a| 91在线精品一区二区| 国产精品国产精品国产专区不蜜| 波多野结衣亚洲| 国产精品国产三级国产有无不卡 | 8x8x8国产精品| 午夜精品久久久久影视| 69精品人人人人| 热久久一区二区| 精品国产91亚洲一区二区三区婷婷| 激情文学综合网| 久久久久久久久久久久电影| 国产精一区二区三区| 国产亚洲成aⅴ人片在线观看| 国产成人自拍网| 国产精品麻豆一区二区 | 日本不卡的三区四区五区| 欧美精品乱码久久久久久按摩 | 亚洲精品国产一区二区精华液| 99久久99久久综合| 樱桃视频在线观看一区| 欧美日韩你懂得| 免费三级欧美电影| 亚洲免费色视频| 91福利视频久久久久| 亚洲成人精品影院| 欧美一卡在线观看| 韩国v欧美v日本v亚洲v| 久久九九久精品国产免费直播| 国产白丝精品91爽爽久久| 国产精品无人区| 91国内精品野花午夜精品| 午夜欧美大尺度福利影院在线看| 欧美一区二区三区日韩| 国产一区二区在线看| 国产精品女同互慰在线看| 在线亚洲欧美专区二区| 日韩高清在线不卡| 久久久www成人免费无遮挡大片| 成人午夜精品一区二区三区| 亚洲人成网站色在线观看| 欧美日韩精品综合在线| 国产在线一区二区| 日韩理论电影院| 欧美老女人在线| 国产精品一区二区视频| 亚洲精品五月天| 欧美一级专区免费大片| 国产成人在线免费| 夜夜精品视频一区二区| 欧美成人精品福利| 99国产精品99久久久久久| 日韩二区三区在线观看| 中文字幕中文字幕在线一区| 欧美日韩一区中文字幕| 国产精品888| 亚洲一区二区三区激情| 久久久亚洲欧洲日产国码αv| 91丝袜美腿高跟国产极品老师| 日韩激情在线观看| 国产精品国产自产拍高清av| 日韩午夜在线观看| a美女胸又www黄视频久久| 日韩专区一卡二卡| 国产精品乱码一区二三区小蝌蚪| 欧美日韩亚洲高清一区二区| 高清国产一区二区三区| 日韩精品福利网| 亚洲精品视频在线| 2020国产精品| 在线播放91灌醉迷j高跟美女| 成人美女视频在线观看| 三级成人在线视频| 亚洲柠檬福利资源导航| 久久久久久久久久久久久夜| 欧美性一区二区| 国产精品一区二区在线播放| 亚洲va中文字幕| 中文字幕一区三区| 26uuu国产日韩综合| 91精品国产一区二区人妖| 91色.com| 成人听书哪个软件好| 乱一区二区av| 亚洲电影视频在线| 亚洲男帅同性gay1069| 国产丝袜欧美中文另类| 日韩视频免费观看高清完整版在线观看| 97久久久精品综合88久久| 国产自产2019最新不卡| 日韩国产在线观看| 亚洲国产你懂的| 亚洲另类中文字| 亚洲欧洲日产国产综合网| 久久久久国产精品免费免费搜索| 日韩一区二区三区视频| 9191久久久久久久久久久| 欧美日韩一区二区三区免费看| 94-欧美-setu| 成人激情电影免费在线观看| 国产精品自在在线| 国模大尺度一区二区三区| 蜜臀久久久久久久| 日韩1区2区日韩1区2区| 亚洲va欧美va人人爽| 亚洲成人一区在线| 亚洲成人激情自拍| 偷拍一区二区三区| 亚洲国产日韩在线一区模特| 亚洲愉拍自拍另类高清精品| 亚洲乱码国产乱码精品精98午夜 | 精品国精品国产尤物美女| 777奇米四色成人影色区| 欧美日本一区二区三区四区| 欧美日韩一区久久| 欧美日韩精品一区二区三区 | 国产精品1区2区3区在线观看| 激情六月婷婷久久| 欧美日韩一区二区不卡| 欧美亚洲国产一区二区三区| 色综合天天综合给合国产| 从欧美一区二区三区| 成人激情电影免费在线观看| 99精品欧美一区二区三区综合在线| 不卡一区中文字幕| 99久久久精品| 91国产成人在线| 在线免费观看日本欧美| 欧美性色aⅴ视频一区日韩精品| 欧美又粗又大又爽| 在线中文字幕一区| 欧美日韩电影在线| 欧美一区二区三区四区久久| 日韩欧美国产一区在线观看| 欧美mv日韩mv| 欧美国产日产图区| 亚洲免费观看高清完整版在线观看熊| 一二三四社区欧美黄| 亚洲va国产天堂va久久en| 日韩精品亚洲一区二区三区免费| 捆绑调教一区二区三区| 国产盗摄一区二区三区| 国产aⅴ精品一区二区三区色成熟| 懂色av一区二区夜夜嗨| 不卡的电视剧免费网站有什么| 91在线视频网址| 777色狠狠一区二区三区| 精品国产电影一区二区| 欧美激情综合在线| 亚洲狠狠丁香婷婷综合久久久| 婷婷丁香激情综合| 国产精品中文有码| 91蝌蚪国产九色| 91精品国产aⅴ一区二区| 久久日一线二线三线suv| 国产精品久久久久久久裸模| 亚洲国产精品久久一线不卡| 麻豆久久久久久久| 91丝袜呻吟高潮美腿白嫩在线观看| 欧美日韩成人综合| 国产欧美精品区一区二区三区| 亚洲精品国久久99热| 另类小说综合欧美亚洲|