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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch17.htm

?? good book for learning c++ standard language
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
<PRE><FONT COLOR="#0066FF">0:    enum LEVEL { NONE, LOW, MEDIUM, HIGH };
1:    const int FALSE = 0;
2:    const int TRUE = 1;
3:    typedef int BOOL;
4:    
5:     #define DEBUGLEVEL HIGH
6:    
7:     #include &lt;iostream.h&gt;
8:     #include &lt;string.h&gt;
9:    
10:     #if DEBUGLEVEL &lt; LOW  // must be medium or high
11:     #define ASSERT(x)
12:     #else
13:     #define ASSERT(x) \
14:         if (! (x)) \
15:         { \
16:            cout &lt;&lt; &quot;ERROR!! Assert &quot; &lt;&lt; #x &lt;&lt; &quot; failed\n&quot;; \
17:            cout &lt;&lt; &quot; on line &quot; &lt;&lt; __LINE__  &lt;&lt; &quot;\n&quot;; \
18:            cout &lt;&lt; &quot; in file &quot; &lt;&lt; __FILE__ &lt;&lt; &quot;\n&quot;;  \
19:         }
20:     #endif
21:    
22:     #if DEBUGLEVEL &lt; MEDIUM
23:     #define EVAL(x)
24:     #else
25:     #define EVAL(x) \
26:       cout &lt;&lt; #x &lt;&lt; &quot;:\t&quot; &lt;&lt; x &lt;&lt; endl;
27:     #endif
28:    
29:    #if DEBUGLEVEL &lt; HIGH
30:     #define PRINT(x)
31:     #else
32:     #define PRINT(x) \
33:       cout &lt;&lt; x &lt;&lt; endl;
34:     #endif
35:    
36:    
37:     class String
38:     {
39:        public:
40:           // constructors
41:           String();
42:           String(const char *const);
43:           String(const String &amp;);
44:           ~String();
45:    
46:           char &amp; operator[](int offset);
47:           char operator[](int offset) const;
48:    
49:           String &amp; operator= (const String &amp;);
50:           int GetLen()const { return itsLen; }
51:           const char * GetString() const 
52:            { return itsString; }
53:           BOOL Invariants() const;
54: 
55:        private:
56:           String (int);         // private constructor
57:           char * itsString;
58:           unsigned short itsLen;
59:     };
60:    
61:     BOOL String::Invariants() const
62:     {
63:         PRINT(&quot;(String Invariants Checked)&quot;);
64:         return ( (BOOL) (itsLen &amp;&amp; itsString) || 
65:             (!itsLen &amp;&amp; !itsString) );
66:     }
67:    
68:     class Animal
69:     {
70:     public:
71:        Animal():itsAge(1),itsName(&quot;John Q. Animal&quot;)
72:            {ASSERT(Invariants());}
73:    
74:        Animal(int, const String&amp;);
75:        ~Animal(){}
76:    
77:        int GetAge() 
78:            {  
79:                ASSERT(Invariants()); 
80:                return itsAge;
81:            }
82:    
83:        void SetAge(int Age) 
84:            { 
85:                ASSERT(Invariants()); 
86:                itsAge = Age; 
87:                ASSERT(Invariants());
88:            }
89:        String&amp; GetName() 
90:            { 
91:                ASSERT(Invariants()); 
92:                return itsName;  
93:            }
94:    
95:        void SetName(const String&amp; name)
96:            { 
97:                ASSERT(Invariants()); 
98:                itsName = name; 
99:                ASSERT(Invariants());
100:            }
101:    
102:        BOOL Invariants();
103:     private:
104:        int itsAge;
105:        String itsName;
106:     };
107:    
108:     BOOL Animal::Invariants()
109:     {
110:        PRINT(&quot;(Animal Invariants Checked)&quot;);
111:        return (itsAge &gt; 0 &amp;&amp; itsName.GetLen());
112:     }
113:    
114:     int main()
115:     {
116:        const int AGE = 5;
117:        EVAL(AGE);
118:        Animal sparky(AGE,&quot;Sparky&quot;);
119:        cout &lt;&lt; &quot;\n&quot; &lt;&lt; sparky.GetName().GetString();
120:        cout &lt;&lt; &quot; is &quot;;
121:        cout &lt;&lt; sparky.GetAge() &lt;&lt; &quot; years old.&quot;;
122:        sparky.SetAge(8);
123:        cout &lt;&lt; &quot;\n&quot; &lt;&lt; sparky.GetName().GetString();
124:        cout &lt;&lt; &quot; is &quot;;
125:        cout &lt;&lt; sparky.GetAge() &lt;&lt; &quot; years old.&quot;;
126:        return 0;
<TT>127: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: AGE:     5
 (String Invariants Checked)
 (String Invariants Checked)
 (String Invariants Checked)
 (String Invariants Checked)
 (String Invariants Checked)
 (String Invariants Checked)
 (String Invariants Checked)
 (String Invariants Checked)
 (String Invariants Checked)
 (String Invariants Checked)

Sparky is (Animal Invariants Checked)
5 Years old. (Animal Invariants Checked)
 (Animal Invariants Checked)
 (Animal Invariants Checked)

Sparky is (Animal Invariants Checked)
8 years old. (String Invariants Checked)
 (String Invariants Checked)

// run again with DEBUG = MEDIUM

AGE:     5
Sparky is 5 years old.
Sparky is 8 years old.
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>On lines 10 to 20, the <TT>assert()</TT>
macro is defined to be stripped if <TT>DEBUGLEVEL</TT> is less than <TT>LOW</TT>
(that is, <TT>DEBUGLEVEL</TT> is <TT>NONE</TT>). If any debugging is enabled, the
<TT>assert()</TT> macro will work. On line 23, <TT>EVAL</TT> is declared to be stripped
if <TT>DEBUG</TT> is less than <TT>MEDIUM</TT>; if <TT>DEBUGLEVEL</TT> is <TT>NONE</TT>
or <TT>LOW</TT>, <TT>EVAL</TT> is stripped.<BR>
Finally, on lines 29-34, the <TT>PRINT</TT> macro is declared to be stripped if <TT>DEBUGLEVEL</TT>
is less than <TT>HIGH</TT>. <TT>PRINT</TT> is used only when <TT>DEBUGLEVEL</TT>
is <TT>HIGH</TT>; you can eliminate this macro by setting <TT>DEBUGLEVEL</TT> to
<TT>MEDIUM</TT> and still maintain your use of <TT>EVAL</TT> and <TT>assert()</TT>.</P>
<P><TT>PRINT</TT> is used within the <TT>Invariants()</TT> methods to print an informative
message. <TT>EVAL</TT> is used on line 117 to evaluate the current value of the constant
integer <TT>AGE</TT>.


<BLOCKQUOTE>
	<P>
<HR>
<B>DO</B> use CAPITALS for your macro names. This is a pervasive convention, and
	other programmers will be confused if you don't. <B>DON'T</B> allow your macros to
	have side effects. Don't increment variables or assign values from within a macro.
	<B>DO</B> surround all arguments with parentheses in macro functions. 
<HR>


</BLOCKQUOTE>

<H3 ALIGN="CENTER"><A NAME="Heading42"></A><FONT COLOR="#000077">Summary</FONT></H3>
<P>Today you learned more details about working with the preprocessor. Each time
you run the compiler, the preprocessor runs first and translates your preprocessor
directives such as <TT>#define</TT> and <TT>#ifdef</TT>.</P>
<P>The preprocessor does text substitution, although with the use of macros these
can be somewhat complex. By using <TT>#ifdef</TT>,<TT> #else</TT>, and <TT>#ifndef</TT>,
you can accomplish conditional compilation, compiling in some statements under one
set of conditions and in another set of statements under other conditions. This can
assist in writing programs for more than one platform and is often used to conditionally
include debugging information.</P>
<P>Macro functions provide complex text substitution based on arguments passed at
compile time to the macro. It is important to put parentheses around every argument
in the macro to ensure the correct substitution takes place.</P>
<P>Macro functions, and the preprocessor in general, are less important in C++ than
they were in C. C++ provides a number of language features, such as <TT>const</TT>
variables and templates, that offer superior alternatives to use of the preprocessor.
<H3 ALIGN="CENTER"><A NAME="Heading43"></A><FONT COLOR="#000077">Q&amp;A</FONT></H3>

<DL>
	<DD><B>Q. If C++ offers better alternatives than the preprocessor, why is this option
	still available?<BR>
	</B><BR>
	<B>A.</B> First, C++ is backward-compatible with C, and all significant parts of
	C must be supported in C++. Second, there are some uses of the preprocessor that
	are still used frequently in C++, such as inclusion guards.<BR>
	<BR>
	<B>Q. Why use macro functions when you can use a regular function?<BR>
	</B><BR>
	<B>A.</B> Macro functions are expanded inline and are used as a substitute for repeatedly
	typing the same commands with minor variations. Again, though, templates offer a
	better alternative.<BR>
	<BR>
	<B>Q. How do you know when to use a macro versus an inline function?<BR>
	</B><BR>
	<B>A.</B> Often it doesn't matter much; use whichever is simpler. However, macros
	offer character substitution, stringizing, and concatenation. None of these is available
	with functions.<BR>
	<BR>
	<B>Q. What is the alternative to using the preprocessor to print interim values during
	debugging?</B><BR>
	<B><BR>
	A.</B> The best alternative is to use <TT>watch</TT> statements within a debugger.
	For information on <TT>watch</TT> statements, consult your compiler or debugger documentation.<BR>
	<BR>
	<B>Q. How do you decide when to use an assert() and when to throw an exception?<BR>
	</B><BR>
	<B>A.</B> If the situation you're testing can be true without your having committed
	a programming error, use an exception. If the only reason for this situation to ever
	be true is a bug in your program, use an <TT>assert()</TT>.
</DL>

<H3 ALIGN="CENTER"><A NAME="Heading44"></A><FONT COLOR="#000077">Workshop</FONT></H3>
<P>The Workshop provides quiz questions to help you solidify your understanding of
the material covered and exercises to provide you with experience in using what you've
learned. Try to answer the quiz and exercise questions before checking the answers
in Appendix D, and make sure you understand the answers before continuing to the
next chapter.
<H4 ALIGN="CENTER"><A NAME="Heading45"></A><FONT COLOR="#000077">Quiz</FONT></H4>

<DL>
	<DD><B>1.</B> What is an inclusion guard?<BR>
	<B><BR>
	2. </B>How do you instruct your compiler to print the contents of the intermediate
	file showing the effects of the preprocessor?<BR>
	<B><BR>
	3.</B> What is the difference between <TT>#define debug 0</TT> and <TT>#undef debug</TT>?<BR>
	<B><BR>
	4.</B> Name four predefined macros.<BR>
	<B><BR>
	5.</B> Why can't you call <TT>Invariants()</TT> as the first line of your constructor?
</DL>

<H4 ALIGN="CENTER"><A NAME="Heading46"></A><FONT COLOR="#000077">Exercises</FONT></H4>

<DL>
	<DD><B>1.</B> Write the inclusion guard statements for the header file <TT>STRING.H</TT>.<BR>
	<B><BR>
	2.</B> Write an <TT>assert()</TT> macro that prints an error message and the file
	and line number if debug level is 2, just a message (without file and line number)
	if the level is 1, and does nothing if the level is 0.<BR>
	<B><BR>
	3.</B> Write a macro <TT>DPrint</TT> that tests if <TT>DEBUG</TT> is defined and,
	if it is, prints the value passed in as a parameter.<BR>
	<B><BR>
	4.</B> Write a function that prints an error message. The function should print the
	line number and filename where the error occurred. Note that the line number and
	filename are passed in to this function.<BR>
	<B><BR>
	5.</B> How would you call the preceding error function?<BR>
	<B><BR>
	6.</B> Wr

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色婷婷综合中文久久一本| 欧美亚洲禁片免费| 色悠久久久久综合欧美99| 日韩视频免费直播| 亚洲视频香蕉人妖| 国产精品1024| 日韩久久久久久| 一区二区不卡在线播放| 国产成人在线看| 日韩欧美中文一区二区| 自拍偷在线精品自拍偷无码专区| 五月天亚洲精品| 日本精品视频一区二区| 国产日韩精品一区二区浪潮av| 亚洲bt欧美bt精品777| 99精品久久99久久久久| 精品福利视频一区二区三区| 婷婷丁香激情综合| 91成人在线精品| 国产精品不卡一区| 国产传媒一区在线| 久久久午夜精品理论片中文字幕| 婷婷夜色潮精品综合在线| 色综合久久中文综合久久牛| 中文字幕亚洲在| 成人午夜激情视频| 国产欧美日韩三级| 国产福利91精品| 久久精品人人做人人爽人人| 亚洲国产精品99久久久久久久久 | 国内精品久久久久影院薰衣草| 亚洲免费成人av| 亚洲第一二三四区| 91搞黄在线观看| 一区二区三区成人在线视频| 成人综合婷婷国产精品久久| 中文字幕精品一区二区精品绿巨人 | 欧美一级艳片视频免费观看| 国产成人综合在线| 久久久精品免费免费| 国产一区二区剧情av在线| 久久久精品免费观看| 国产乱码精品一区二区三区忘忧草| 在线观看日韩av先锋影音电影院| 日韩高清不卡在线| 在线观看91精品国产麻豆| 亚洲国产精品嫩草影院| 欧美天堂亚洲电影院在线播放| 亚洲自拍偷拍av| 日韩一区二区三区电影在线观看| 麻豆精品在线观看| 久久精品一区二区| 91视频你懂的| 日韩高清不卡一区二区三区| 欧美不卡123| 99在线精品一区二区三区| 亚洲激情一二三区| 日韩欧美国产麻豆| 成人激情开心网| 亚洲一区二区三区在线看| 91精品久久久久久久99蜜桃| 国产精品资源在线看| 成人欧美一区二区三区白人 | 狠狠色综合播放一区二区| 国产成人在线色| 夜夜精品视频一区二区| 成人v精品蜜桃久久一区| 亚洲女子a中天字幕| 91精品国产综合久久精品麻豆| 国产综合久久久久影院| 亚洲美腿欧美偷拍| 欧美一级欧美一级在线播放| 成人免费视频免费观看| 亚洲国产精品视频| 欧美激情一区二区三区蜜桃视频| 在线观看亚洲专区| 国产一区二区三区av电影| 亚洲乱码国产乱码精品精小说| 日韩视频一区二区| 一本色道久久加勒比精品| 免费成人结看片| 亚洲欧美日韩国产综合在线| 欧美xingq一区二区| 91福利在线导航| 成人晚上爱看视频| 麻豆精品在线观看| 极品美女销魂一区二区三区 | 在线精品视频小说1| 亚洲欧美影音先锋| 91精品国产综合久久久久久久久久 | 自拍偷拍国产亚洲| 欧美电影免费观看高清完整版| 91啪在线观看| 国产成人亚洲综合a∨猫咪| 香蕉久久夜色精品国产使用方法| 国产精品青草综合久久久久99| 91精品黄色片免费大全| 色综合久久综合网| 高清成人在线观看| 极品少妇xxxx精品少妇偷拍| 国产欧美日韩精品a在线观看| 午夜激情综合网| 精品国产乱码91久久久久久网站| 欧美在线一区二区| av在线播放不卡| 成人免费av在线| 国产精品一区在线| 韩国精品在线观看| 日日摸夜夜添夜夜添精品视频| 亚洲激情网站免费观看| 亚洲视频在线观看一区| 一区免费观看视频| 日本一二三四高清不卡| 国产欧美一区视频| 国产欧美一区二区三区沐欲| 久久免费的精品国产v∧| 精品久久国产97色综合| 精品理论电影在线观看| 精品理论电影在线| 精品av久久707| 国产亚洲一本大道中文在线| 精品国产乱码久久久久久影片| 日韩精品在线一区| 337p日本欧洲亚洲大胆精品 | 不卡的av电影| 日本系列欧美系列| 欧美在线高清视频| 91视频在线观看| 欧美丝袜自拍制服另类| 欧美日韩精品一区二区三区四区 | 久久午夜色播影院免费高清| 2023国产精品自拍| 国产欧美久久久精品影院| 中文字幕成人网| 亚洲三级电影网站| 亚洲丰满少妇videoshd| 免费精品视频最新在线| 国产黄色精品网站| 91性感美女视频| 欧美日本一区二区三区| 2欧美一区二区三区在线观看视频| 久久人人超碰精品| 国产精品入口麻豆原神| 亚洲综合视频在线观看| 日本免费在线视频不卡一不卡二| 激情综合一区二区三区| 寂寞少妇一区二区三区| 国产精品久久久久久久久久免费看| 精品国产免费人成在线观看| 久久66热偷产精品| 韩国在线一区二区| 91影视在线播放| 日韩亚洲欧美在线| 国产精品美女一区二区在线观看| 一区二区三区精密机械公司| 麻豆成人91精品二区三区| 大桥未久av一区二区三区中文| 欧美日韩一二三| 国产欧美日韩综合| 日韩中文字幕1| 成人av在线网站| 欧美一区二区三区影视| 综合色中文字幕| 久久国产精品一区二区| 色吧成人激情小说| 久久久www免费人成精品| 一区二区三区久久| 国产大陆a不卡| 91麻豆精品国产91久久久久| 中文字幕一区三区| 久久99久久久久| 欧美日韩视频不卡| 国产精品不卡在线| 久久这里只有精品6| 欧美性色aⅴ视频一区日韩精品| 成人ar影院免费观看视频| 亚洲色图制服丝袜| 国产一区欧美二区| 日韩一区二区中文字幕| 一区二区在线看| 成人av在线一区二区| 久久久精品综合| 久久99久久99| 欧美精品乱人伦久久久久久| 亚洲男人电影天堂| 成人小视频在线| 国产女主播在线一区二区| 久久狠狠亚洲综合| 欧美一级二级三级蜜桃| 亚洲一区二区五区| 色噜噜久久综合| 亚洲女与黑人做爰| 91丝袜高跟美女视频| 中文字幕在线不卡| av一区二区三区在线| 国产精品热久久久久夜色精品三区 | 韩国午夜理伦三级不卡影院| 欧美一区二区性放荡片| 亚洲成人免费电影| 欧美日韩国产区一|