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

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

?? ch17.htm

?? good book for learning c++ standard language
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
Output: Enter a number (0 to quit): 1
You entered: 1.  Square(1): 1. Cube(1): 1.
Enter a number (0 to quit): 2
You entered: 2.  Square(2): 4. Cube(2): 8.
Enter a number (0 to quit): 3
You entered: 3.  Square(3): 9. Cube(3): 27.
Enter a number (0 to quit): 4
You entered: 4.  Square(4): 16. Cube(4): 64.
Enter a number (0 to quit): 5
You entered: 5.  Square(5): 25. Cube(5): 125.
Enter a number (0 to quit): 6
You entered: 6.  Square(6): 36. Cube(6): 216.
Enter a number (0 to quit): 0
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>On lines 3 and 4, two inline
functions are declared: <TT>Square()</TT> and <TT>Cube()</TT>. Each is declared to
be inline, so like a macro function these will be expanded in place for each call,
and there will be no function call overhead.<BR>
As a reminder, expanded inline means that the content of the function will be placed
into the code wherever the function call is made (for example, on line 16). Because
the function call is never made, there is no overhead of putting the return address
and the parameters on the stack.</P>
<P>On line 16, the function <TT>Square</TT> is called, as is the function <TT>Cube</TT>.
Again, because these are inline functions, it is exactly as if this line had been
written like this:</P>
<PRE><FONT COLOR="#0066FF">16:          cout &lt;&lt; &quot;.  Square(&quot; &lt;&lt; x &lt;&lt; &quot;): &quot;  &lt;&lt; x * x &lt;&lt; &quot;. 
	Cube(&quot; &lt;&lt; x &lt;&lt; &#194;&quot;): &quot; &lt;&lt; x * x * x &lt;&lt;
&quot;.&quot; &lt;&lt; endl;</FONT></PRE>
<P>
<PRE><FONT COLOR="#0066FF"></FONT></PRE>
<H3 ALIGN="CENTER"><A NAME="Heading24"></A><FONT COLOR="#000077">String Manipulation</FONT></H3>
<P>The preprocessor provides two special operators for manipulating strings in macros.
The stringizing operator (<TT>#</TT>) substitutes a quoted string for whatever follows
the stringizing operator. The concatenation operator bonds two strings together into
one.
<H4 ALIGN="CENTER"><A NAME="Heading25"></A><FONT COLOR="#000077">Stringizing</FONT></H4>
<P>The stringizing operator puts quotes around any characters following the operator,
up to the next white space. Thus, if you write</P>
<PRE><FONT COLOR="#0066FF">#define WRITESTRING(x) cout &lt;&lt; #x
</FONT></PRE>
<P>and then call</P>
<PRE><FONT COLOR="#0066FF">WRITESTRING(This is a string);
</FONT></PRE>
<P>the precompiler will turn it into</P>
<PRE><FONT COLOR="#0066FF">cout &lt;&lt; &quot;This is a string&quot;;
</FONT></PRE>
<P>Note that the string <TT>This is a string</TT> is put into quotes, as required
by <TT>cout</TT>.
<H4 ALIGN="CENTER"><A NAME="Heading26"></A><FONT COLOR="#000077">Concatenation</FONT></H4>
<P>The concatenation operator allows you to bond together more than one term into
a new word. The new word is actually a token that can be used as a class name, a
variable name, an offset into an array, or anywhere else a series of letters might
appear.</P>
<P>Assume for a moment that you have five functions, named <TT>fOnePrint</TT>, <TT>fTwoPrint</TT>,
<TT>fThreePrint</TT>, <TT>fFourPrint</TT>, and <TT>fFivePrint</TT>. You can then
declare:</P>
<PRE><FONT COLOR="#0066FF">#define fPRINT(x) f ## x ## Print
</FONT></PRE>
<P>and then use it with <TT>fPRINT(Two)</TT> to generate <TT>fTwoPrint</TT> and with
<TT>fPRINT(Three)</TT> to generate <TT>fThreePrint.</TT></P>
<P>At the conclusion of Week 2, a <TT>PartsList</TT> class was developed. This list
could only handle objects of type <TT>List</TT>. Let's say that this list works well,
and you'd like to be able to make lists of animals, cars, computers, and so forth.</P>
<P>One approach would be to create <TT>AnimalList</TT>, <TT>CarList</TT>, <TT>ComputerList</TT>,
and so on, cutting and pasting the code in place. This will quickly become a nightmare,
as every change to one list must be written to all the others.</P>
<P>An alternative is to use macros and the concatenation operator. For example, you
could define</P>
<PRE><FONT COLOR="#0066FF">#define Listof(Type)  class Type##List \
{ \
public: \
Type##List(){} \
private:          \
int itsLength; \
};
</FONT></PRE>
<P>This example is overly sparse, but the idea would be to put in all the necessary
methods and data. When you were ready to create an <TT>AnimalList</TT>, you would
write</P>
<PRE><FONT COLOR="#0066FF">Listof(Animal)
</FONT></PRE>
<P>and this would be turned into the declaration of the <TT>AnimalList</TT> class.
There are some problems with this approach, all of which are discussed in detail
on Day 19, when templates are discussed.
<H3 ALIGN="CENTER"><A NAME="Heading27"></A><FONT COLOR="#000077">Predefined Macros</FONT></H3>
<P>Many compilers predefine a number of useful macros, including <TT>__DATE__</TT>,
<TT>__TIME__</TT>, <TT>__LINE__</TT>, and <TT>__FILE__</TT>. Each of these names
is surrounded by two underscore characters to reduce the likelihood that the names
will conflict with names you've used in your program.</P>
<P>When the precompiler sees one of these macros, it makes the appropriate substitutes.
For <TT>__DATE__</TT>, the current date is substituted. For <TT>__TIME__</TT>, the
current time is substituted. <TT>__LINE__</TT> and <TT>__FILE__</TT> are replaced
with the source code line number and filename, respectively. You should note that
this substitution is made when the source is precompiled, not when the program is
run. If you ask the program to print <TT>__DATE__</TT>, you will not get the current
date; instead, you will get the date the program was compiled. These defined macros
are very useful in debugging.
<H3 ALIGN="CENTER"><A NAME="Heading28"></A><FONT COLOR="#000077">assert()</FONT></H3>
<P>Many compilers offer an <TT>assert()</TT> macro. The <TT>assert()</TT> macro returns
<TT>TRUE</TT> if its parameter evaluates <TT>TRUE</TT> and takes some kind of action
if it evaluates <TT>FALSE</TT>. Many compilers will abort the program on an <TT>assert()</TT>
that fails; others will throw an exception (see Day 20, &quot;Exceptions and Error
Handling&quot;).</P>
<P>One powerful feature of the <TT>assert()</TT> macro is that the preprocessor collapses
it into no code at all if <TT>DEBUG</TT> is not defined. It is a great help during
development, and when the final product ships there is no performance penalty nor
increase in the size of the executable version of the program.</P>
<P>Rather than depending on the compiler-provided <TT>assert()</TT>, you are free
to write your own <TT>assert()</TT> macro. Listing 17.5 provides a simple <TT>assert()</TT>
macro and shows its use.</P>
<P><A NAME="Heading29"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 17.5. A simple
assert() macro.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">1:     // Listing 17.5 ASSERTS
2:     #define DEBUG
3:     #include &lt;iostream.h&gt;
4:
5:     #ifndef DEBUG
6:        #define ASSERT(x)
7:     #else
8:        #define ASSERT(x) \
9:                 if (! (x)) \
10:                { \
11:                   cout &lt;&lt; &quot;ERROR!! Assert &quot; &lt;&lt; #x &lt;&lt; &quot; failed\n&quot;; \
12:                   cout &lt;&lt; &quot; on line &quot; &lt;&lt; __LINE__  &lt;&lt; &quot;\n&quot;; \
13:                   cout &lt;&lt; &quot; in file &quot; &lt;&lt; __FILE__ &lt;&lt; &quot;\n&quot;;  \
14:                }
15:    #endif
16:
17:
18:    int main()
19:    {
20:       int x = 5;
21:       cout &lt;&lt; &quot;First assert: \n&quot;;
22:       ASSERT(x==5);
23:       cout &lt;&lt; &quot;\nSecond assert: \n&quot;;
24:       ASSERT(x != 5);
25:       cout &lt;&lt; &quot;\nDone.\n&quot;;
26:     return 0;
<TT>27: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: First assert:

Second assert:
ERROR!! Assert x !=5 failed
 on line 24
 in file test1704.cpp
Done.
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>On line 2, the term <TT>DEBUG</TT>
is defined. Typically, this would be done from the command line (or the IDE) at compile
time, so you can turn this on and off at will. On lines 8-14, the <TT>assert()</TT>
macro is defined. Typically, this would be done in a header file, and that header
(<TT>ASSERT.HPP</TT>) would be included in all your implementation files.<BR>
<BR>
On line 5, the term <TT>DEBUG</TT> is tested. If it is not defined, <TT>assert()</TT>
is defined to create no code at all. If <TT>DEBUG</TT> is defined, the functionality
defined on lines 8-14 is applied.</P>
<P>The <TT>assert()</TT> itself is one long statement, split across seven source
code lines, as far as the precompiler is concerned. On line 9, the value passed in
as a parameter is tested; if it evaluates <TT>FALSE</TT>, the statements on lines
11-13 are invoked, printing an error message. If the value passed in evaluates <TT>TRUE</TT>,
no action is taken.
<H4 ALIGN="CENTER"><A NAME="Heading31"></A><FONT COLOR="#000077">Debugging with assert()</FONT></H4>
<P>When writing your program, you will often know deep down in your soul that something
is true: a function has a certain value, a pointer is valid, and so forth. It is
the nature of bugs that what you know to be true might not be so under some conditions.
For example, you know that a pointer is valid, yet the program crashes. <TT>assert()</TT>
can help you find this type of bug, but only if you make it a regular practice to
use <TT>assert()</TT> liberally in your code. Every time you assign or are passed
a pointer as a parameter or function return value, be sure to assert that the pointer
is valid. Any time your code depends on a particular value being in a variable, <TT>assert()</TT>
that that is true.</P>
<P>There is no penalty for frequent use of <TT>assert()</TT>; it is removed from
the code when you undefine debugging. It also provides good internal documentation,
reminding the reader of what you believe is true at any given moment in the flow
of the code.
<H4 ALIGN="CENTER"><A NAME="Heading32"></A><FONT COLOR="#000077">assert() Versus
Exceptions</FONT></H4>
<P>On Day 20, you will learn how to work with exceptions to handle error conditions.
It is important to note that <TT>assert()</TT> is not intended to handle runtime
error conditions such as bad data, out-of-memory conditions, unable to open file,
and so forth. <TT>assert()</TT> is created to catch programming errors only. That
is, if an <TT>assert()</TT> &quot;fires,&quot; you know you have a bug in your code.</P>
<P>This is critical, because when you ship your code to your customers, instances
of <TT>assert()</TT> will be removed. You can't depend on an <TT>assert()</TT> to
handle a runtime problem, because the <TT>assert()</TT> won't be there.</P>
<P>It is a common mistake to use <TT>assert()</TT> to test the return value from
a memory assignment:</P>
<PRE><FONT COLOR="#0066FF">Animal *pCat = new Cat;
Assert(pCat);   // bad use of assert
pCat-&gt;SomeFunction();
</FONT></PRE>
<P>This is a classic programming error; every time the programmer runs the program,
there is enough memory and the <TT>assert()</TT> never fires. After all, the programmer
is running with lots of extra RAM to speed up the compiler, debugger, and so forth.
The programmer then ships the executable, and the poor user, who has less memory,
reaches this part of the program and the call to <TT>new</TT> fails and returns <TT>NULL</TT>.
The <TT>assert()</TT>, however, is no longer in the code and there is nothing to
indicate that the pointer points to <TT>NULL</TT>. As soon as the statement <TT>pCat-&gt;SomeFunction()</TT>
is reached, the program crashes.</P>
<P>Getting <TT>NULL</TT> back from a memory assignment is not a programming error,
although it is an exceptional situation. Your program must be able to recover from
this condition, if only by throwing an exception. Remember: The entire <TT>assert()</TT>
statement is gone when <TT>DEBUG</TT> is undefined. Exceptions are covered in detail
on Day 20.
<H4 ALIGN="CENTER"><A NAME="Heading33"></A><FONT COLOR="#000077">Side Effects</FONT></H4>
<P>It is not uncommon to find that a bug appears only after the instances of <TT>assert()</TT>
are removed. This is almost always due to the program unintentionally depending on
side effects of things done in <TT>assert()</TT> and other debug-only code. For example,
if you write</P>
<PRE><FONT COLOR="#0066FF">ASSERT (x = 5)
</FONT></PRE>
<P>when you mean to test whether <TT>x == 5</TT>, you will create a particularly
nasty bug.</P>
<P>Let's say that just prior to this <TT>assert()</TT> you called a function that
set <TT>x</TT> equal to 0. With this <TT>assert()</TT> you think you are testing
whether <TT>x</TT> is equal to 5; in fact, you are setting <TT>x</TT> equal to 5.
The test returns <TT>TRUE</TT>, because <TT>x = 5</TT> not only sets <TT>x</TT> to
5, but returns the value <TT>5</TT>, and because 5 is non-zero it evaluates as <TT>TRUE</TT>.</P>
<P>Once you pass the <TT>assert()</TT> statement, <TT>x</TT> really is equal to 5
(you just set it!). Your program runs just fine. You're ready to ship it, so you
turn off debugging. Now the <TT>assert()</TT> disappears, and you are no longer setting
<TT>x</TT> to 5. Because <TT>x</TT> was set to 0 just before this, it remains at
0 and your program breaks.</P>
<P>In frustration, you turn debugging back on, but hey! Presto! The bug is gone.
Once again, this is rather funny to watch, but not to live through, so be very careful
about side effects in debugging code. If you see a bug that only appears when debugging
is turned off, take a look at your debugging code with an eye out for nasty side
effects.
<H4 ALIGN="CENTER"><A NAME="Heading34"></A><FONT COLOR="#000077">Class Invariants</FONT></H4>
<P>Most classes have some conditions that should always be true whenever you are
finished with a class member function. These class invariants are the sine qua non
of your class. For example, it may be true that your <TT>CIRCLE</TT> object should
never have a radius of zero, or that your <TT>ANIMAL</TT> should always have an age
greater than zero and less than 100.</P>
<P>It can be very helpful to declare an <TT>Invariants()</TT> method that returns
<TT>TRUE</TT> only if each of these conditions is still true. You can then <TT>ASSERT(Invariants())</TT>
at the start and completion of every class method. The exception would be that your
<TT>Invariants()</TT> would not expect to return <TT>TRUE</TT> before your constructor
runs or after your destructor ends. Listing 17.6 demonstrates the use of the <TT>Invariants()</TT>
method in a trivial class.</P>
<P><A NAME="Heading35"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 17.6. Using
Invariants().</B></FONT></P>
<PRE><FONT COLOR="#0066FF">0:    #define DEBUG
1:    #define SHOW_INVARIANTS
2:    #include &lt;iostream.h&gt;
3:    #include &lt;string.h&gt;
4:    
5:    #ifndef DEBUG
6:    #define ASSERT(x)
7:    #else
8:    #define ASSERT(x) \
9:                if (! (x)) \
10:                { \
11:                   cout &lt;&lt; &quot;ERROR!! Assert &quot; &lt;&lt; #x &lt;&lt; &quot; failed\n&quot;; \
12:                   cout &lt;&lt; &quot; on line &quot; &lt;&lt; __LINE__  &lt;&lt; &quot;\n&quot;; \
13:                   cout &lt;&lt; &quot; in file &quot; &lt;&lt; __FILE__ &lt;&lt; &quot;\n&quot;;  \
14:                }
15:    #endif
16:    
17:    
18:    const int FALSE = 0;
19:    const int TRUE = 1;
20:    typedef int BOOL;
21: 
22:    
23:    class String
24:    {
25:       public:
26:          // constructors
27:          String();
28:          String(const char *const);
29:          String(const String &amp;);
30:          ~String();
31:    
32:          char &amp; operator[](int offset);
33:          char operator[](int offset) const;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产在线精品免费| 久久久精品影视| 欧美一区二区在线免费播放| 欧美一级淫片007| 久久精品在线免费观看| 亚洲欧美另类小说| 日韩黄色免费电影| 国产高清不卡二三区| 色哟哟日韩精品| 日韩一区二区免费视频| 欧美国产精品v| 亚洲一区二区黄色| 国产一区二区三区观看| 色国产综合视频| 精品日韩在线观看| 亚洲视频综合在线| 美女视频黄a大片欧美| 成人黄色777网| 欧美精品久久一区二区三区| 国产日产亚洲精品系列| 亚洲国产综合色| 国产精品一级黄| 欧美日韩中文另类| 国产午夜精品在线观看| 亚洲成人午夜电影| 成人性生交大片免费看在线播放| 欧美日韩久久久一区| 欧美经典三级视频一区二区三区| 亚洲第一会所有码转帖| 国产mv日韩mv欧美| 欧美精品vⅰdeose4hd| 国产精品国产三级国产aⅴ原创| 日本网站在线观看一区二区三区 | 国产一区在线不卡| 欧美在线综合视频| 国产午夜精品一区二区三区视频| 亚洲成av人**亚洲成av**| 国产成人免费xxxxxxxx| 91精品国产高清一区二区三区| 国产精品国产馆在线真实露脸| 美腿丝袜亚洲一区| 在线观看视频一区二区| 国产精品视频免费看| 另类调教123区| 欧美日韩一二三| 国产精品色哟哟| 国产剧情在线观看一区二区| 欧美巨大另类极品videosbest | 成人在线视频首页| 欧美一区二区免费视频| 亚洲制服丝袜av| www.日本不卡| 久久女同互慰一区二区三区| 日本网站在线观看一区二区三区| 在线观看日韩一区| 亚洲同性同志一二三专区| 国产99精品视频| www国产成人| 免费成人美女在线观看.| 欧美日韩精品一区二区天天拍小说 | 日韩三级免费观看| 日韩精品成人一区二区在线| 欧美在线一区二区| 亚洲精品国产精品乱码不99| 99国产欧美另类久久久精品| 欧美国产乱子伦| 国产成人av电影| 久久精品一区二区三区四区| 国产揄拍国内精品对白| 欧美成人r级一区二区三区| 亚洲a一区二区| 欧美性大战xxxxx久久久| 亚洲美女淫视频| 91麻豆精品视频| 亚洲视频香蕉人妖| 一本色道a无线码一区v| 亚洲女人小视频在线观看| 91香蕉视频污| 一区二区成人在线视频| 欧洲视频一区二区| 亚洲国产精品一区二区www| 欧洲人成人精品| 亚洲一区二区免费视频| 欧美日本乱大交xxxxx| 日韩精品视频网站| 日韩欧美电影一二三| 麻豆国产精品视频| 久久久久久久电影| 福利一区二区在线观看| 18欧美乱大交hd1984| 91小视频在线免费看| 亚洲一区二区三区三| 欧美日高清视频| 青青草国产精品亚洲专区无| 精品少妇一区二区三区在线播放 | 日韩一级免费观看| 激情综合网天天干| 欧美激情一区二区三区在线| 一本大道综合伊人精品热热| 亚洲国产精品一区二区www在线| 91精品国产色综合久久不卡蜜臀 | 欧美一区二区三级| 精品伊人久久久久7777人| 国产亚洲综合性久久久影院| 成人18精品视频| 亚洲国产综合在线| 精品国产一区二区三区久久影院 | 国产亚洲精久久久久久| 91视频一区二区三区| 天天综合日日夜夜精品| 精品入口麻豆88视频| 成人av动漫在线| 亚洲va天堂va国产va久| 亚洲精品一线二线三线| 91在线播放网址| 日韩电影免费一区| 欧美国产欧美亚州国产日韩mv天天看完整| 色综合久久久网| 美女视频网站久久| 成人欧美一区二区三区在线播放| 欧美精品三级在线观看| 国产suv精品一区二区883| 午夜精品久久久久影视| 日韩精品一级中文字幕精品视频免费观看| 精品国产区一区| 色噜噜狠狠一区二区三区果冻| 日本va欧美va精品| 中文字幕在线观看一区| 7777精品伊人久久久大香线蕉经典版下载| 国内不卡的二区三区中文字幕 | 欧美四级电影网| 国产精品自拍av| 亚洲国产精品天堂| 日本一区二区三区免费乱视频| 欧美三级午夜理伦三级中视频| 久久精品国产一区二区三| 亚洲免费资源在线播放| 精品国产乱码久久久久久图片| 91亚洲资源网| 激情小说欧美图片| 亚洲第一精品在线| 国产精品国产三级国产普通话99| 欧美一级日韩不卡播放免费| 91啪在线观看| 国产一区不卡视频| 日韩黄色免费电影| 亚洲欧美色图小说| 久久久久国产成人精品亚洲午夜 | 麻豆精品一区二区三区| 亚洲乱码中文字幕综合| 国产亚洲污的网站| 欧美一级高清大全免费观看| 一本大道久久a久久精二百| 国产精品一区二区三区四区| 视频在线观看国产精品| 国产精品国产三级国产aⅴ无密码 国产精品国产三级国产aⅴ原创 | 日韩三级高清在线| 欧美亚洲动漫制服丝袜| 91网页版在线| 国产不卡免费视频| 国内欧美视频一区二区| 无码av中文一区二区三区桃花岛| 亚洲人成在线播放网站岛国| 国产视频一区二区在线观看| 欧美成人一区二区三区| 亚洲成av人影院| 亚洲另类色综合网站| 国产精品久久久一本精品| 久久青草国产手机看片福利盒子 | 久久99精品国产.久久久久| 亚洲成国产人片在线观看| 一区二区三区国产豹纹内裤在线| 国产精品久久夜| 中文字幕成人在线观看| 国产亚洲人成网站| 久久蜜桃av一区二区天堂| 欧美大片免费久久精品三p| 91精品国模一区二区三区| 91麻豆精品国产91久久久更新时间 | 欧美日韩精品免费| 日本韩国欧美在线| 日本韩国欧美国产| 色综合天天性综合| 精品国产sm最大网站免费看| 欧美一区二区三区四区高清| 欧美欧美欧美欧美首页| 欧美日韩国产综合视频在线观看 | 日韩精品一级二级| 日本伊人色综合网| 久久国产精品色婷婷| 另类人妖一区二区av| 激情综合网天天干| 国产成人亚洲综合a∨婷婷图片| 国产精品一色哟哟哟| 大陆成人av片| 99久久婷婷国产| 91久久精品一区二区三| 欧美日韩在线播放| 6080日韩午夜伦伦午夜伦| 日韩女优毛片在线|