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

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

?? ch17.htm

?? good book for learning c++ standard language
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
34:    
35:          String & operator= (const String &);
36:          int GetLen()const { return itsLen; }
37:          const char * GetString() const { return itsString; }
38:          BOOL Invariants() const;
39:    
40:       private:
41:          String (int);         // private constructor
42:          char * itsString;
43:         // unsigned short itsLen;
44:          int itsLen;
45:    };
46:    
47:    // default constructor creates string of 0 bytes
48:    String::String()
49:    {
50:       itsString = new char[1];
51:       itsString[0] = `\0';
52:       itsLen=0;
53:       ASSERT(Invariants());
54:    }
55:    
56:    // private (helper) constructor, used only by
57:    // class methods for creating a new string of
58:    // required size.  Null filled.
59:    String::String(int len)
60:    {
61:       itsString = new char[len+1];
62:       for (int i = 0; i<=len; i++)
63:          itsString[i] = `\0';
64:       itsLen=len;
65:       ASSERT(Invariants());
66:    }
67:    
68:    // Converts a character array to a String
69:    String::String(const char * const cString)
70:    {
71:       itsLen = strlen(cString);
72:       itsString = new char[itsLen+1];
73:       for (int i = 0; i<itsLen; i++)
74:          itsString[i] = cString[i];
75:       itsString[itsLen]='\0';
76:       ASSERT(Invariants());
77:    }
78:    
79:    // copy constructor
80:    String::String (const String & rhs)
81:    {
82:       itsLen=rhs.GetLen();
83:       itsString = new char[itsLen+1];
84:       for (int i = 0; i<itsLen;i++)
85:          itsString[i] = rhs[i];
86:       itsString[itsLen] = `\0';
87:       ASSERT(Invariants());
88:    }
89:    
90:    // destructor, frees allocated memory
91:    String::~String ()
92:    {
93:       ASSERT(Invariants());
94:       delete [] itsString;
95:       itsLen = 0;
96:    }
97:    
98:    // operator equals, frees existing memory
99:    // then copies string and size
100:    String& String::operator=(const String & rhs)
101:    {
102:       ASSERT(Invariants());
103:       if (this == &rhs)
104:          return *this;
105:       delete [] itsString;
106:       itsLen=rhs.GetLen();
107:       itsString = new char[itsLen+1];
108:       for (int i = 0; i<itsLen;i++)
109:          itsString[i] = rhs[i];
110:       itsString[itsLen] = `\0';
111:       ASSERT(Invariants());
112:       return *this;
113:    }
114:    
115:    //non constant offset operator, returns
116:    // reference to character so it can be
117:    // changed!
118:    char & String::operator[](int offset)
119:    {
120:       ASSERT(Invariants());
121:       if (offset > itsLen)
122:          return itsString[itsLen-1];
123:       else
124:          return itsString[offset];
125:       ASSERT(Invariants());
126:    }
127:    
128:    // constant offset operator for use
129:    // on const objects (see copy constructor!)
130:    char String::operator[](int offset) const
131:    {
132:       ASSERT(Invariants());
133:       if (offset > itsLen)
134:          return itsString[itsLen-1];
135:       else
136:          return itsString[offset];
137:       ASSERT(Invariants());
138:    }
139:    
140:    
141:    BOOL String::Invariants() const
142:    {
143:    #ifdef SHOW_INVARIANTS
144:       cout << " String OK ";
145:    #endif
146:        return ( (itsLen && itsString) || 
147:          (!itsLen && !itsString) );
148:     }
149:    
150:     class Animal
151:     {
152:     public:
153:        Animal():itsAge(1),itsName("John Q. Animal")
154:           {ASSERT(Invariants());}
155:         Animal(int, const String&);
156:        ~Animal(){}
157:        int GetAge() {  ASSERT(Invariants()); return itsAge;}
158:        void SetAge(int Age) 
159:        { 
160:             ASSERT(Invariants()); 
161:             itsAge = Age;              
162:             ASSERT(Invariants()); 
163:        }
164:         String& GetName() 
165:         { 
166:               ASSERT(Invariants()); 
167:               return itsName;  
168:         }
169:         void SetName(const String& name)
170:               { 
171:               ASSERT(Invariants()); 
172:               itsName = name; 
173:               ASSERT(Invariants());
174:         }
175:         BOOL Invariants();
176:      private:
177:         int itsAge;
178:         String itsName;
179:      };
180:    
181:      Animal::Animal(int age, const String& name):
182:      itsAge(age),
183:      itsName(name)
184:      {
185:         ASSERT(Invariants());
186:      }
187:    
188:      BOOL Animal::Invariants()
189:      {
190:      #ifdef SHOW_INVARIANTS
191:         cout << " Animal OK ";
192:      #endif
193:         return (itsAge > 0 && itsName.GetLen());
194:      }
195:    
196:      int main()
197:      {
198:         Animal sparky(5,"Sparky");
199:         cout << "\n" << sparky.GetName().GetString() << " is ";
200:         cout << sparky.GetAge() << " years old.";
201:         sparky.SetAge(8);
202:         cout << "\n" << sparky.GetName().GetString() << " is ";
203:         cout << sparky.GetAge() << " years old.";
204:         return 0;
<TT>205: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: String OK  String OK  String OK  String OK  String OK  
String OK  String OK  Animal OK  String OK  Animal OK
Sparky is  Animal OK 5 years old. Animal OK  Animal OK  
Animal OK  Sparky is  Animal OK 8 years old. String OK 
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>On lines 6-16, the <TT>assert()</TT>
macro is defined. If <TT>DEBUG</TT> is defined, this will write out an error message
when the <TT>assert()</TT> macro evaluates <TT>FALSE</TT>.<BR>
On line 38, the <TT>String</TT> class member function <TT>Invariants()</TT> is declared;
it is defined on lines 141-148. The constructor is declared on lines 48-54, and on
line 53, after the object is fully constructed, <TT>Invariants()</TT> is called to
confirm proper construction.</P>
<P>This pattern is repeated for the other constructors, and the destructor calls
<TT>Invariants()</TT> only before it sets out to destroy the object. The remaining
class functions call <TT>Invariants()</TT> both before taking any action and then
again before returning. This both affirms and validates a fundamental principal of
C++: Member functions other than constructors and destructors should work on valid
objects and should leave them in a valid state.</P>
<P>On line 175, class <TT>Animal</TT> declares its own <TT>Invariants()</TT> method,
implemented on lines 188-194. Note on lines 154, 157, 160, and 162 that inline functions
can call the <TT>Invariants()</TT> method.
<H4 ALIGN="CENTER"><A NAME="Heading36"></A><FONT COLOR="#000077">Printing Interim
Values</FONT></H4>
<P>In addition to asserting that something is true using the <TT>assert()</TT> macro,
you may want to print the current value of pointers, variables, and strings. This
can be very helpful in checking your assumptions about the progress of your program,
and in locating off-by-one bugs in loops. Listing 17.7 illustrates this idea.</P>
<P><A NAME="Heading37"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 17.7. Printing
values in DEBUG mode.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">1:     // Listing 17.7 - Printing values in DEBUG mode
2:     #include &lt;iostream.h&gt;
3:     #define DEBUG
4:
5:     #ifndef DEBUG
6:     #define PRINT(x)
7:     #else
8:     #define PRINT(x) \
9:        cout &lt;&lt; #x &lt;&lt; &quot;:\t&quot; &lt;&lt; x &lt;&lt; endl;
10:    #endif
11:
12:    enum BOOL { FALSE, TRUE } ;
13:
14:    int main()
15:    {
16:       int x = 5;
17:       long y = 73898l;
18:       PRINT(x);
19:       for (int i = 0; i &lt; x; i++)
20:       {
21:          PRINT(i);
22:       }
23:
24:       PRINT (y);
25:       PRINT(&quot;Hi.&quot;);
26:       int *px = &amp;x;
27:       PRINT(px);
28:       PRINT (*px);
29:     return 0;
<TT>30: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: x:      5
i:      0
i:      1
i:      2
i:      3
i:      4
y:      73898
&quot;Hi.&quot;:  Hi.
px:       0x2100 (You may receive a value other than 0x2100)
*px:    5
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>The macro on lines 5-10 provides
printing of the current value of the supplied parameter. Note that the first thing
fed to <TT>cout</TT> is the stringized version of the parameter; that is, if you
pass in <TT>x</TT>, <TT>cout</TT> receives <TT>&quot;x&quot;</TT>.<BR>
<BR>
Next, <TT>cout</TT> receives the quoted string <TT>&quot;:\t&quot;</TT>, which prints
a colon and then a tab. Third, <TT>cout</TT> receives the value of the parameter
(<TT>x</TT>), and then finally, <TT>endl</TT>, which writes a new line and flushes
the buffer.
<H4 ALIGN="CENTER"><A NAME="Heading39"></A><FONT COLOR="#000077">Debugging Levels</FONT></H4>
<P>In large, complex projects, you may want more control than simply turning <TT>DEBUG</TT>
on and off. You can define debug levels and test for these levels when deciding which
macros to use and which to strip out.</P>
<P>To define a level, simply follow the <TT>#define DEBUG</TT> statement with a number.
While you can have any number of levels, a common system is to have four levels:
<TT>HIGH</TT>, <TT>MEDIUM</TT>, <TT>LOW</TT>, and <TT>NONE</TT>. Listing 17.8 illustrates
how this might be done, using the <TT>String</TT> and <TT>Animal</TT> classes from
Listing 17.6. The definitions of the class methods other than <TT>Invariants()</TT>
have been left out to save space because they are unchanged from Listing 17.6.


<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>To compile this code, copy lines
	43-136 of Listing 17.6 between lines 64 and 65 of this listing. 
<HR>


</BLOCKQUOTE>

<P><A NAME="Heading40"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 17.8. Levels
of debugging.</B></FONT></P>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文字幕一区二区三区在线播放 | 精品系列免费在线观看| 国产嫩草影院久久久久| 欧美日本高清视频在线观看| 成人丝袜高跟foot| 老司机精品视频导航| 一区二区三区在线观看视频| 久久亚洲综合色一区二区三区 | 欧美一级理论片| 99v久久综合狠狠综合久久| 蜜桃免费网站一区二区三区| 一区二区三区欧美日韩| 美国十次了思思久久精品导航| 自拍偷拍国产精品| 精品国产伦一区二区三区免费| 欧美亚洲动漫精品| 99国产精品久久久久久久久久 | 蜜桃视频一区二区三区在线观看| 亚洲人成在线播放网站岛国| 国产欧美一区二区三区网站 | 亚洲精品久久久蜜桃| 国产午夜精品理论片a级大结局| 51精品视频一区二区三区| 91久久精品国产91性色tv| 成人免费av资源| 国产综合色视频| 美女视频网站久久| 免费精品视频最新在线| 五月婷婷综合激情| 一区二区三区日韩欧美精品| 自拍偷拍欧美精品| 最新欧美精品一区二区三区| 国产精品视频观看| 欧美国产日韩a欧美在线观看| 久久网站最新地址| 欧美精品一区二区三区久久久| 欧美一区二区三区播放老司机| 欧美日韩另类国产亚洲欧美一级| 色婷婷精品久久二区二区蜜臀av| 99久精品国产| 99天天综合性| 91蜜桃网址入口| 91免费版在线看| 色婷婷综合久久久久中文 | 午夜精品久久久久久久99樱桃| 一区二区三区不卡在线观看| 亚洲男同性视频| 亚洲一区二区综合| 亚洲成a天堂v人片| 日本在线不卡视频一二三区| 麻豆一区二区99久久久久| 看电视剧不卡顿的网站| 精品一区二区三区在线观看国产| 精品一区二区三区欧美| 国产一区二区三区香蕉| 国产91在线观看| 91在线视频播放地址| 欧美主播一区二区三区| 欧美高清你懂得| 久久亚洲欧美国产精品乐播| 欧美极品aⅴ影院| 亚洲狼人国产精品| 日韩—二三区免费观看av| 另类综合日韩欧美亚洲| 国产精品高潮呻吟| 国产亚洲精久久久久久| 日韩视频在线永久播放| 国产精品区一区二区三| 欧美色图在线观看| 97久久人人超碰| 欧美性做爰猛烈叫床潮| 国产精品人妖ts系列视频| 蜜桃精品视频在线| 欧美亚洲日本一区| 国产精品美女久久久久aⅴ国产馆| 免费人成精品欧美精品| 在线中文字幕不卡| 国产精品久久久久久户外露出 | 欧美不卡在线视频| 午夜久久久久久| 91麻豆免费视频| 国产网站一区二区| 免费在线观看视频一区| 欧美日韩国产123区| 亚洲精品欧美在线| 成人免费不卡视频| 久久精品亚洲麻豆av一区二区 | 亚洲欧美日韩久久| 丰满放荡岳乱妇91ww| 久久综合国产精品| 美女视频第一区二区三区免费观看网站| 日本韩国视频一区二区| 亚洲免费大片在线观看| 白白色 亚洲乱淫| 日本一区二区成人在线| 国产一区不卡视频| www成人在线观看| 韩国成人在线视频| 精品国产区一区| 久久99精品国产.久久久久久| 91麻豆精品国产91久久久久久| 亚洲chinese男男1069| 欧美影视一区二区三区| 亚洲亚洲人成综合网络| 欧美性猛交xxxxxxxx| 亚洲一区二区欧美| 欧美日韩精品福利| 日本不卡视频一二三区| 日韩欧美中文字幕公布| 免费在线视频一区| 久久综合狠狠综合| 国产成人激情av| 久久精品男人的天堂| 国产精品一区二区在线观看网站| 国产三级一区二区三区| 国产成人在线免费| 国产精品伦理一区二区| 91亚洲精品乱码久久久久久蜜桃| 亚洲三级在线免费| 欧美亚洲一区二区三区四区| 三级欧美韩日大片在线看| 91精品婷婷国产综合久久性色| 免费黄网站欧美| 久久久五月婷婷| av不卡免费电影| 一区二区三区成人在线视频| 在线不卡一区二区| 韩国视频一区二区| 国产精品夫妻自拍| 欧美午夜在线一二页| 免费欧美在线视频| 国产色综合一区| 在线观看国产91| 另类的小说在线视频另类成人小视频在线| 欧美mv和日韩mv的网站| 成人伦理片在线| 午夜激情一区二区| 久久综合九色综合97婷婷女人| 成人av集中营| 亚洲sss视频在线视频| 久久男人中文字幕资源站| 91一区二区三区在线观看| 日韩av在线播放中文字幕| 日本一区二区视频在线观看| 在线日韩一区二区| 国产在线日韩欧美| 亚洲精品乱码久久久久久 | 亚洲一区二区3| 欧美不卡一区二区三区| 99久久国产综合色|国产精品| 天天射综合影视| 亚洲国产精品成人综合色在线婷婷| 日本韩国一区二区三区| 国产一区在线精品| 亚洲综合男人的天堂| 久久久91精品国产一区二区精品| 色婷婷精品大在线视频| 韩国女主播一区二区三区| 一区二区三区在线免费视频| 久久嫩草精品久久久精品一| 欧美手机在线视频| 成人网男人的天堂| 奇米色777欧美一区二区| 亚洲欧洲av另类| 精品国产伦理网| 欧美日韩国产色站一区二区三区| 国产乱理伦片在线观看夜一区| 一区二区三区四区不卡在线| 久久人人爽爽爽人久久久| 欧美日韩一区二区三区视频| 成人午夜免费电影| 美脚の诱脚舐め脚责91| 亚洲一区二区三区激情| 国产精品欧美极品| 欧美tickling挠脚心丨vk| 欧美日韩亚洲综合| 色欧美片视频在线观看在线视频| 国产精品亚洲人在线观看| 蜜臀99久久精品久久久久久软件| 亚洲一区二区欧美激情| 日韩美女视频一区| 久久久不卡网国产精品二区| 欧美一区二区久久久| 91久久精品一区二区| 99热99精品| 国产 欧美在线| 国产乱码精品一品二品| 精品制服美女丁香| 蜜臀av性久久久久蜜臀aⅴ流畅| 亚洲一区二区三区四区在线免费观看| 国产精品国产三级国产普通话三级 | 国产福利一区二区三区| 麻豆91在线播放| 欧美在线观看视频一区二区三区| 成人小视频免费在线观看| 国产麻豆精品在线观看| 韩国精品主播一区二区在线观看| 蜜臀99久久精品久久久久久软件 | 欧美午夜理伦三级在线观看| 91美女福利视频|