锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久精品国产亚洲沈樵,午夜福利91久久福利,久久久中文字幕 http://m.shnenglu.com/liyuxia713/category/10183.html韞掕窔鍓嶈鑰?/description>zh-cn Sun, 06 Jun 2010 18:21:37 GMT Sun, 06 Jun 2010 18:21:37 GMT 60 鍐呭瓨綆$悊 http://m.shnenglu.com/liyuxia713/archive/2010/06/05/117211.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sat, 05 Jun 2010 01:34:00 GMT http://m.shnenglu.com/liyuxia713/archive/2010/06/05/117211.html http://m.shnenglu.com/liyuxia713/comments/117211.html http://m.shnenglu.com/liyuxia713/archive/2010/06/05/117211.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/117211.html http://m.shnenglu.com/liyuxia713/services/trackbacks/117211.html 鎵╁睍闃呰
鍐呭瓨鐨勪笁縐嶅垎閰嶆柟寮忥細
1錛?nbsp;浠庨潤鎬佸瓨鍌ㄥ尯鍒嗛厤錛氭鏃剁殑鍐呭瓨鍦ㄧ▼搴忕紪璇戠殑鏃跺欏凡緇忓垎閰嶅ソ錛屽茍涓斿湪紼嬪簭鐨勬暣涓繍琛屾湡闂撮兘瀛樺湪銆傚叏灞鍙橀噺錛宻tatic鍙橀噺絳夊湪姝ゅ瓨鍌ㄣ?/p>
2錛?nbsp;鍦ㄦ爤鍖哄垎閰嶏細鐩稿叧浠g爜鎵ц鏃跺垱寤猴紝鎵ц緇撴潫鏃惰鑷姩閲婃斁銆傚眬閮ㄥ彉閲忓湪姝ゅ瓨鍌ㄣ傛爤鍐呭瓨鍒嗛厤榪愮畻鍐呯疆浜庡鐞嗗櫒鐨勬寚浠ら泦涓紝鏁堢巼楂橈紝浣嗗閲忔湁闄愩?/p>
3錛?nbsp;鍦ㄥ爢鍖哄垎閰嶏細鍔ㄦ佸垎閰嶅唴瀛樸傜敤new/malloc鏃跺紑杈燂紝delete/free鏃墮噴鏀俱傜敓瀛樻湡鐢辯敤鎴鋒寚瀹氾紝鐏墊椿銆備絾鏈夊唴瀛樻硠闇茬瓑闂銆?/p>
甯歌鍐呭瓨閿欒鍙婂絳?/p>
1錛?nbsp;鍐呭瓨鍒嗛厤鏈垚鍔燂紝鍗磋浣跨敤銆?/p>
瀵圭瓥錛氫嬌鐢ㄥ唴瀛樹箣鍓嶆鏌ユ槸鍚﹀垎閰嶆垚鍔熴傜敤p!=NULL鍒ゆ柇銆?/p>
2錛?nbsp;鍐呭瓨鍒嗛厤鎴愬姛錛屾湭鍒濆鍖栧氨琚嬌鐢ㄣ?/p>
鍐呭瓨鐨勭己鐪佸兼病鏈夌粺涓鐨勬爣鍑嗐傚ぇ閮ㄥ垎緙栬瘧鍣ㄤ互0浣滀負鍒濆鍊鹼紝浣嗕笉瀹屽叏鏄?/p>
瀵圭瓥錛氬唴瀛樺垵濮嬪寲鏃惰祴鍒濆箋?/p>
3錛?nbsp;鍐呭瓨鎿嶄綔瓚婄晫銆?/p>
瀵圭瓥錛氬彧鑳芥槸灝忓績浜嗐?/p>
4錛?nbsp;閲婃斁浜嗗唴瀛橈紝浠嶇劧浣跨敤銆?/p>
錛?錛?nbsp; 浣跨敤鏄劇ずdelete鍜宖ree鐨勯噹鎸囬拡銆?/p>
瀵圭瓥錛氶噴鏀懼畬鍐呭瓨錛屽皢鎸囬拡緗負NULL銆?/p>
錛?錛?nbsp; 浣跨敤闅愬紡delete鍜宖ree鐨勯噹鎸囬拡銆備富瑕佹槸鎸囧嚱鏁拌繑鍥炴寚鍚戞爤鍐呭瓨鐨勬寚閽堟垨寮曠敤銆?/p>
瀵圭瓥錛氬綋鐒舵槸涓嶈榪斿洖灝卞彲浠ヤ簡銆?/p>
5錛?nbsp;鏈噴鏀懼唴瀛橈紝瀵艱嚧鍐呭瓨娉勯湶銆?/p>
鐢╪ew/malloc寮杈熶簡鍐呭瓨錛屾病鐢╠elete/free閲婃斁.
瀵圭瓥錛歯ew鍜宒elete鐨勪釜鏁頒竴瀹氱浉鍚岋紱malloc鍜宖ree鐨勪釜鏁頒竴瀹氱浉鍚岋紱new[]鍜孾]delete涓瀹氬搴斻?br> 紺轟緥1錛氳繑鍥炴寚鍚戞爤絀洪棿鐨勬寚閽?br>
1 char * test1() 2 { 3 char str[] = " Hello World! " ; 4 return str; 5 } 6 7 char * test2() 8 { 9 char * str = " Hello World! " ; 10 return str; 11 }12 13 char * test3() 14 { 15 static char str[] = " Hello World! " ; 16 return str; 17 }18 19 void main() 20 { 21 char * str = NULL; 22 23 str = test1(); 24 cout << str << endl; // 鍨冨溇淇℃伅 25 26 str = test2(); 27 cout << str << endl; // ok 28 // str[1] = 'A' ; // error.璇曞浘淇敼甯稿瓧絎︿覆 29 // str = NULL; // error.璇曞浘淇敼甯稿瓧絎︿覆 30 31 str = test3(); 32 cout << str << endl; 33 }34
杈撳嚭緇撴灉錛?br>涔辯爜
Hello World!
Hello World!紺轟緥2錛?/span>new 鍜?/span>delete 铏界劧瀵瑰簲錛屼絾 delete 閲婃斁涓嶆垚鍔?/span>
void main() { char * p = new char [ 4 ]; p = " ppp " ; delete []p; }
榪愯鏃墮敊璇?/span>P 铏界劧鏄姩鎬佸紑杈熺殑鍐呭瓨錛屼絾鍦ㄧ浜屾潯璇彞鍚?/span>p 宸茬粡鎸囧悜浜嗛潤鎬佸瓨鍌ㄥ尯涓婄殑鍦板潃錛岃屽鎸囧悜闈欐佸瓨鍌ㄥ尯鐨勬寚閽堟槸涓嶈兘鐢?/span>delete 閲婃斁鐨勩傛鏃朵笉浠呰繍琛屾椂閿欒錛岃繕鏈夊唴瀛樻硠闇層?/span>
]]>sscanf http://m.shnenglu.com/liyuxia713/archive/2010/04/25/113530.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 25 Apr 2010 12:13:00 GMT http://m.shnenglu.com/liyuxia713/archive/2010/04/25/113530.html http://m.shnenglu.com/liyuxia713/comments/113530.html http://m.shnenglu.com/liyuxia713/archive/2010/04/25/113530.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/113530.html http://m.shnenglu.com/liyuxia713/services/trackbacks/113530.html int sscanf(const char* str, const char* format, ...)functions: Reads data from str and stores them according to the parameter format into the locations given by the additional arguments. Locations pointed by each additional argument are filled with their corresponding type of value specified in the format string. In the format:Whitespace character: the function will read and ignore any whitespace characters which are encounterd before the next non-whitespace character. Non-whitespace character: except percentage signs(%): any character that is not either a whitespace character or part of a format specifier causes the function to read the next character from str, compare it to this non-whitespace character and if it matches, it is discarded and the function continues with the next character of format and str. If the character does not match, the function fails and returns.Return Value: On success. the function returns the number of items successfully read. On failure: In the case of an input failure before any data could be successfully read, EOF is returnded.
// 榛樿浠ョ┖鏍煎垎闅攕tr涓轟笉鍚屽瓧絎︿覆,榪斿洖姝g‘杈撳叆鐨勫彉閲忎釜鏁?nbsp; char buf1[ 512 ] = { 0 } ; cout << sscanf( " abc def gh " , " %s " ,buf1) << endl; // 1 cout << buf1 << endl; // abc // 鍙互浣垮涓竴璧峰瓨鍏?nbsp; char buf2[ 512 ] = { 0 } ; char buf3[ 512 ] = { 0 } ; cout << sscanf( " abc 2def gh " , " %s%s " ,buf2,buf3) << endl; // 2 cout << buf2 << endl; // abc cout << buf3 << endl; // 2def // 絀烘牸鎴杅ormat鏍煎紡浠ュ鐨勫瓧絎﹀鏋滃尮閰嶅垯涓庡墠涓涓瓧絎︿覆涓璧瘋緭鍏ワ紝鍚﹀垯鍋滄錛岄鍑?nbsp; char buf4[ 512 ] = { 0 } ; char buf5[ 512 ] = { 0 } ; cout << sscanf( " abc 2def gh " , " %s,%s " ,buf4,buf5) << endl; // 1 cout << buf4 << endl; // abc cout << buf5 << endl; // nothing char buf6[ 512 ] = { 0 } ; char buf7[ 512 ] = { 0 } ; // 娉ㄦ剰涓や釜%s涔嬮棿鐨勭┖鏍間笉鍙皯 sscanf( " abc 2def gh " , " %s 2%s " ,buf6,buf7); cout << buf6 << endl; // abc cout << buf7 << endl; // def // 褰撶劧涓嶅彧鏄瓧絎︿覆褰㈠紡鐨勶紝鍏朵粬涔熼兘鍙互 char buf8[ 512 ] = { 0 } ; int a; cout << sscanf( " abc 2def gh " , " %*s %d " , & a) << endl; // 1 cout << a << endl; // 2 // Failure int b; cout << sscanf( " abc " , " %d " , & b) << endl; // 0
]]> sprintf http://m.shnenglu.com/liyuxia713/archive/2010/04/25/113525.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 25 Apr 2010 11:23:00 GMT http://m.shnenglu.com/liyuxia713/archive/2010/04/25/113525.html http://m.shnenglu.com/liyuxia713/comments/113525.html http://m.shnenglu.com/liyuxia713/archive/2010/04/25/113525.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/113525.html http://m.shnenglu.com/liyuxia713/services/trackbacks/113525.html http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/
Portotype: int printf(char* str, const char* format, parameters);
Writes into the array pointed by str a C string consisting on a sequence of data formatted as the format argument specifies. After the format parameter, the function expects at least as many additional arguments as specified in format .
This function behaves exactly as printf does, but writing its result to a string instead of stdout . The size of the array passed as str should be enough to contain the entire formatted string .
Return value:
On success, the total number of characters written is returned. This count does not include the additional null-character automatically appended at the end of the string.
// Success // The size of str is long enough // the number of additional number match with the format const int size = 25 ; char * str = new char [size]; //same as int flag1 = sprintf(str,"%s is written to str.","Test","tEST"); int flag1 = sprintf(str, " %s is written to str. " , " Test " ); // Console: 23-Test is written to str cout << flag1 << " - " << str << endl;
On failure, a negative number is returned.
// Failure1 // additional arguments numbers is less than specified is format // the second %s transmited as unrecognizable words const int size = 25 ; char * str = new char [size]; int flag2 = sprintf(str, " %s %s tttttttttttt " , " Test " ); // Console: 19--Test @ tttttttttttt cout << flag2 << " -- " << str << endl;
// Failure2:the size of str is not long enough // 鍦╠ev c++涓嶈兘榪愯錛寁c6.0娌掓湁闂 const int size = 25 ; char * str = new char [size]; int flag3 = sprintf(str, " %s jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj " , " Test " ); // VC6.0 Console: Test jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj // Dev c++: Console: the same as vc6.0 but throws an cannot read memory exception cout << flag3 << " -- " << str << endl;
娌℃湁嫻嬭瘯鍑轟粈涔堟椂鍊欏嚭閿欒繑鍥炶礋鍊煎憿錛侊紒璋佺粰鎴戜竴涓緥瀛愶紵
]]> 鎸囬拡瀛︿範4--鍚堟垚鏋愭瀯鍑芥暟鍋氫簡浠涔?/title> http://m.shnenglu.com/liyuxia713/archive/2010/04/19/112952.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Mon, 19 Apr 2010 00:49:00 GMT http://m.shnenglu.com/liyuxia713/archive/2010/04/19/112952.html http://m.shnenglu.com/liyuxia713/comments/112952.html http://m.shnenglu.com/liyuxia713/archive/2010/04/19/112952.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/112952.html http://m.shnenglu.com/liyuxia713/services/trackbacks/112952.html 涓庡鍒舵瀯閫犲嚱鏁板拰澶嶅埗鎿嶄綔絎︿笉鍚岋紝緙栬瘧鍣ㄦ繪槸鎻愪緵鍚堟垚鏋愭瀯鍑芥暟銆?br> 鍚堟垚鏋愭瀯鍑芥暟鍋氫粈涔堬紵 鎸夊璞″垱寤烘椂鐨勯嗗簭鎾ら攢姣忎釜闈瀞tatic鎴愬憳錛屽寘鎷寚閽堟垚鍛樸?br>鍙笉榪囦笉鍒犻櫎鎸囬拡鎴愬憳鎵鎸囧悜鐨勫璞°?/span>
]]> 鎸囬拡瀛︿範3----浣曟椂闇瑕佽嚜琛屽畾涔夋瀽鏋勫嚱鏁?/title> http://m.shnenglu.com/liyuxia713/archive/2010/04/18/112928.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 18 Apr 2010 11:59:00 GMT http://m.shnenglu.com/liyuxia713/archive/2010/04/18/112928.html http://m.shnenglu.com/liyuxia713/comments/112928.html http://m.shnenglu.com/liyuxia713/archive/2010/04/18/112928.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/112928.html http://m.shnenglu.com/liyuxia713/services/trackbacks/112928.html 褰撳湪綾葷殑鏋勯犲嚱鏁頒綋涓敵璇蜂簡璧勬簮(濡傚唴瀛樼┖闂?錛岄渶瑕佸湪瀵硅薄琚攢姣佹椂榪涜閲婃斁鏃躲?
class Test { public : Test( const char * ptr) { if (ptr) { p = new char [strlen(ptr)]; } } ~ Test() { delete[] p; } private : char * p; } ;
]]> 鎸囬拡瀛︿範2--鍐呭瓨娉勯湶 http://m.shnenglu.com/liyuxia713/archive/2010/04/18/112897.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 18 Apr 2010 04:06:00 GMT http://m.shnenglu.com/liyuxia713/archive/2010/04/18/112897.html http://m.shnenglu.com/liyuxia713/comments/112897.html http://m.shnenglu.com/liyuxia713/archive/2010/04/18/112897.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/112897.html http://m.shnenglu.com/liyuxia713/services/trackbacks/112897.html 錛?
1 #include < iostream > 2 using namespace std; 3 4 class Stu 5 { 6 public : 7 Stu(int m):var(m) 8 { 9 cout << var << " constructor called. " << endl; 10 } 11 ~ Stu() { cout << var << " destructor called. " << endl;} 12 private : 13 int var; 14 }; 15 16 17 int main() 18 { 19 Stu * a = new Stu( 20 ); 20 Stu * b = new Stu( 30 ); 21 delete b;22 return 0 ; 23 // or 鍏朵粬闅愯棌寮傚父 24 25 // 瀵艱嚧鍐呭瓨娉勯湶 26 delete a; 27 28 return 0 ; 29 }
]]> 鎸囬拡瀛︿範1--new &delete & destructor http://m.shnenglu.com/liyuxia713/archive/2010/04/18/112892.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 18 Apr 2010 02:58:00 GMT http://m.shnenglu.com/liyuxia713/archive/2010/04/18/112892.html http://m.shnenglu.com/liyuxia713/comments/112892.html http://m.shnenglu.com/liyuxia713/archive/2010/04/18/112892.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/112892.html http://m.shnenglu.com/liyuxia713/services/trackbacks/112892.html 1. 涓鑸寚閽堢殑new&delete
瀵逛簬鎸囬拡 a,delete a 涔嬪悗錛屾寚閽?/span>a 鐨勫湴鍧浠嶇劧鏄師鏉ョ殑鍦板潃(騫朵笉鏄疦ULL)錛屽彧涓嶈繃鎵鎸囧悜鐨勫璞¤閲婃斁浜嗭紝姝ゆ椂鎸囬拡瀛樻斁鐨勫間負闅忔満鐨勶紝鐢辯紪璇戝櫒紜畾銆?br>
1 int * a = new int ( 2 ); 2 cout << " after new : " << endl; 3 cout << " a = " << a << " , " << " *a = " << * a << endl; 4 5 delete a; 6 cout << " after delete: " << endl; 7 if (a == NULL) 8 { 9 cout << " a is null after delete " << endl; 10 }11 else 12 { 13 cout << " a is not null after delete " << endl; 14 }15 cout << " a = " << a << " , " << " *a = " << * a << endl;
// 濂界殑緙栫▼涔犳儻 delete a; a = NULL;
甯歌鏂規硶鍒涘緩鐨勫璞★紝褰撳疄闄呭璞★紙鑰屼笉鏄璞$殑寮曠敤錛夎秴鍑轟綔鐢ㄥ煙鏃訛紝鎵嶄細榪愯鏋愭瀯鍑芥暟 鍔ㄦ佹柟娉曞垱寤虹殑瀵硅薄錛屽綋鍒犻櫎鎸囧悜鍔ㄦ佸垎閰嶅璞$殑鎸囬拡鏃訛紝鎵嶄細榪愯鏋愭瀯鍑芥暟銆?nbsp; 2. 涓鑸被瀵硅薄鐨勫0鏄庝笌鍒濆鍖栵細涓嶇敤new涔熷彲浠ュ畾涔夌被瀵硅薄錛堝尯鍒簬java錛夛紝榛樿璋冩瀽鏋勫嚱鏁?br> 娉細涓烘柟渚跨畝鍗曟紨紺猴紝騫舵病鏈夐伒寰笁娉曞垯
1 class Stu 2 { 3 public : 4 Stu(int m):var(m) 5 { 6 var = m; 7 cout << " constructor called. " << endl; 8 } 9 ~ Stu() { cout << var << " destructor called. " << endl;} 10 private : 11 int var; 12 }; 13 14 void func() 15 { 16 // 璋冪敤鏋勯犲嚱鏁?/span>17 Stu a( 20 ); 18 // 璋冪敤榛樿澶嶅埗鏋勯犲嚱鏁?/span>19 Stu b(a); 20 // 絳変環浜嶴tu temp(b); Stu b(temp); 21 // 鎵浠ユ湁璋冪敤鏋勯犲嚱鏁扮殑榪囩▼ 22 Stu c = 30 ; 23 //閮芥槸鐢ㄩ殣寮忔柟寮忓畾涔夌殑錛屾墍浠ヤ笉鐢╠elete,鑷姩璋冪敤鏋愭瀯鍑芥暟 24 | //娉ㄦ剰鏋愭瀯鐨勯『搴?nbsp; 25 } 26 27 int main() 28 { 29 func(); 30 return 0 ; 31 }
榪欓噷鏈変竴涓渶瑕佹敞鎰忕殑鍦版柟錛屽氨鏄鏋渇unc閲岄潰鐨勪唬鐮佹槸鐩存帴鍐欏湪main閲岀殑鍒欎笉涓瀹氳皟鐢ㄦ瀽鏋勫嚱鏁?nbsp;錛岀敱緙栬瘧鍣ㄥ喅瀹氥?br>涓婇潰鏄痙ev c++, 涓嬮潰鏄痸c6.0鐨勮繍琛岀粨鏋?br>
1 2 int main() 3 { 4 5 // { 6 // 璋冪敤鏋勯犲嚱鏁?/span> 7 Stu a( 20 ); 8 // 璋冪敤榛樿澶嶅埗鏋勯犲嚱鏁?/span> 9 Stu b(a); 10 // 絳変環浜嶴tu temp(b); Stu b(temp); 11 // 鎵浠ユ湁璋冪敤鏋勯犲嚱鏁扮殑榪囩▼ 12 Stu c = 30 ; 13 // new鍑烘潵鐨勬寚閽堝璞★紝蹇呴』鏄劇ずdelete,濡俛,b 14 // 綾誨璞$粨鏉熷眬閮ㄨ寖鍥村悗浼氳嚜鍔ㄨ皟鐢ㄦ瀽鏋勫嚱鏁?nbsp;濡俢 15 // } 16 return 0 ; 17 }
3. 鐢╪ew瀹氫箟綾誨璞?蹇呴』delete 鍔ㄦ佸垎閰嶇殑瀵硅薄鍙湁鍦ㄦ寚鍚戣瀵硅薄鐨勬寚閽堣鍒犻櫎鏃舵墠鎾ら攢銆傚鏋滄病鏈夊垹闄ゆ寚鍚戝姩鎬佸璞$殑鎸囬拡錛屽垯涓嶄細榪愯璇ュ璞$殑鏋愭瀯鍑芥暟錛屽璞″垯涓鐩村瓨鍦紝浠庤屽鑷村唴瀛樻硠闇層?br>甯歌鏂規硶鍒涘緩鐨勫璞★紝褰撳疄闄呭璞★紙鑰屼笉鏄璞$殑寮曠敤錛夎秴鍑轟綔鐢ㄥ煙鏃訛紝鎵嶄細榪愯鏋愭瀯鍑芥暟 鍔ㄦ佹柟娉曞垱寤虹殑瀵硅薄錛屽綋鍒犻櫎鎸囧悜鍔ㄦ佸垎閰嶅璞$殑鎸囬拡鏃訛紝鎵嶄細榪愯鏋愭瀯鍑芥暟銆?br>
1 class Stu 2 { 3 public : 4 Stu(int m):var(m) 5 { 6 var = m; 7 cout << " constructor called. " << endl; 8 } 9 ~ Stu() { cout << var << " destructor called. " << endl;} 10 private : 11 int var; 12 }; 13 14 void func() 15 { 16 // 璋冪敤鏋勯犲嚱鏁?/span>17 Stu * a = new Stu( 20 ); 18 // 璋冪敤榛樿澶嶅埗鏋勯犲嚱鏁?/span>19 Stu * b = new Stu( * a); 20 // 絳変環浜嶴tu temp = new Stu(30); Stu b(temp); 21 // 鎵浠ユ湁璋冪敤鏋勯犲嚱鏁扮殑榪囩▼ 22 Stu c = 30 ; 23 // new鍑烘潵鐨勬寚閽堝璞★紝蹇呴』鏄劇ずdelete,濡俛,b 24 // 綾誨璞$粨鏉熷眬閮ㄨ寖鍥村悗浼氳嚜鍔ㄨ皟鐢ㄦ瀽鏋勫嚱鏁?nbsp;濡俢 25 delete a; 26 delete b;27 } 28 29 int main() 30 { 31 func(); 32 return 0 ; 33 }
]]> 瀹忎笌鍐呰仈(inline)鐨勫尯鍒?杞澆) http://m.shnenglu.com/liyuxia713/archive/2010/03/04/108897.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Thu, 04 Mar 2010 12:22:00 GMT http://m.shnenglu.com/liyuxia713/archive/2010/03/04/108897.html http://m.shnenglu.com/liyuxia713/comments/108897.html http://m.shnenglu.com/liyuxia713/archive/2010/03/04/108897.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/108897.html http://m.shnenglu.com/liyuxia713/services/trackbacks/108897.html 鍏堣漿杞戒笅浜哄鎬葷粨鐨勫畯鍜屾櫘閫氬嚱鏁拌皟鐢ㄧ殑鍖哄埆錛?br>(1)銆佸畯鍙仛綆鍗曠殑瀛楃涓叉浛鎹紝鍑芥暟鏄弬鏁頒紶閫掞紝鎵浠ュ繀鐒舵湁鍙傛暟綾誨瀷媯鏌?鏀寔鍚勭綾誨瀷錛岃屼笉鏄彧鏈夊瓧絎︿覆)銆?br>(2)銆佸畯涓嶇粡璁$畻鑰岀洿鎺ユ浛鎹㈠弬鏁幫紝鍑芥暟璋冪敤鍒欐槸灝嗗弬鏁拌〃杈懼紡姹傚煎啀浼犻掔粰褰㈠弬銆?br>(3)銆佸畯鍦ㄧ紪璇戝墠榪涜錛屽嵆鍏堟浛鎹㈠啀緙栬瘧銆傝屽嚱鏁版槸緙栬瘧鍚庯紝鍦ㄦ墽琛屾椂鎵嶈皟鐢ㄧ殑銆傚畯鍗犵紪璇戞椂闂達紝鑰屽嚱鏁板崰鎵ц鏃墮棿銆?br>(4)銆佸畯鍙傛暟涓嶅崰絀洪棿錛屽洜涓哄彧鍋氬瓧絎︿覆鏇挎崲錛岃屽嚱鏁拌皟鐢ㄦ椂鍙傛暟浼犻掓槸鍙橀噺涔嬮棿鐨勪紶閫掞紝褰㈠弬浣滀負灞閮ㄥ彉閲忓崰鍐呭瓨絀洪棿銆?br>(5)銆佸嚱鏁拌皟鐢ㄩ渶瑕佷繚鐣欑幇鍦猴紝鐒跺悗杞叆璋冪敤鍑芥暟鎵ц錛屾墽琛屽畬姣曞啀榪斿洖涓昏皟鍑芥暟錛岃繖浜涜楄垂鍦ㄥ畯涓槸娌℃湁鐨勩?/p>
浣跨敤瀹忓拰鍐呰仈鍑芥暟閮藉彲浠ヨ妭鐪佸湪鍑芥暟璋冪敤鏂歸潰鐨勬椂闂村拰絀洪棿寮閿銆備簩鑰呴兘鏄負浜嗘彁楂樻晥鐜囷紝浣嗘槸鍗存湁鐫鏄捐憲鐨勫尯鍒細 (1)銆佸湪浣跨敤鏃訛紝瀹忓彧鍋氱畝鍗曠殑棰勫鐞嗗櫒絎﹀彿琛?瀛楃涓?涓殑綆鍗曟浛鎹€傝屽唴鑱斿嚱鏁板彲浠ヨ繘琛屽弬鏁扮被鍨嬫鏌ワ紝涓斿叿鏈夎繑鍥炲?涔熻兘琚己鍒惰漿鎹負鍙漿鎹㈢殑鍚堥傜被鍨?銆?br>(2)銆佸唴鑱斿嚱鏁伴鍏堟槸鍑芥暟錛屽嚱鏁扮殑璁稿鎬ц川閮介傜敤浜庡唴鑱斿嚱鏁?濡傚唴鑱斿嚱鏁板彲浠ラ噸杞?銆?br>(3)銆佸唴鑱斿嚱鏁板彲浠ヤ綔涓烘煇涓被鐨勬垚鍛樺嚱鏁幫紝榪欐牱鍙互浣跨敤綾葷殑淇濇姢鎴愬憳鍜岀鏈夋垚鍛樸傝屽綋涓涓〃杈懼紡娑夊強鍒扮被淇濇姢鎴愬憳鎴栫鏈夋垚鍛樻椂錛屽畯灝變笉鑳藉疄鐜頒簡(鏃犳硶灝唗his鎸囬拡鏀懼湪鍚堥備綅緗?銆?/p>
鍙互鐢ㄥ唴鑱斿嚱鏁板畬鍏ㄦ浛浠e畯銆?br>浣嗘槸鍦ㄤ嬌鐢ㄥ唴鑱斿嚱鏁版椂涔熻娉ㄦ剰錛氫綔涓哄唴鑱斿嚱鏁幫紝鍑芥暟浣撳繀欏誨崄鍒嗙畝鍗曪紝涓嶈兘鍖呭惈寰幆錛屾潯浠訛紝閫夋嫨絳夊鏉傜粨鏋勶紝鍚﹀垯涓嶈兘浣滀負鍐呰仈鍑芥暟銆?br>瀹為檯涓婏紝緙栬瘧鍣ㄧ殑浼樺寲緋葷粺浼氳嚜鍔ㄥ皢涓浜涚畝鍗曞嚱鏁板彉鎴愬唴鑱斿嚱鏁般傝屼竴浜涘鏉傜殑鍑芥暟錛屽嵆浣挎寚瀹氫負鍐呰仈錛岀紪璇戝櫒涔熶細鑷姩褰撲綔鏅氬嚱鏁般?/p>
鏂囩珷鍑哄錛欴IY閮ㄨ惤(http://www.diybl.com/course/3_program/c++/cppxl/20081216/154041.html )
]]> 闅忔満鏁扮殑鐢熸垚 http://m.shnenglu.com/liyuxia713/archive/2010/01/21/106136.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Thu, 21 Jan 2010 07:37:00 GMT http://m.shnenglu.com/liyuxia713/archive/2010/01/21/106136.html http://m.shnenglu.com/liyuxia713/comments/106136.html http://m.shnenglu.com/liyuxia713/archive/2010/01/21/106136.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/106136.html http://m.shnenglu.com/liyuxia713/services/trackbacks/106136.html rand() 鍙幏寰椾吉闅忔満鏁般備絾鏄粎浠呰繖鏍峰啓鐨勮瘽錛屽悓涓孌典唬鐮佹瘡嬈¤繍琛岀▼搴忚幏寰楃殑闅忔満鏁扮浉鍚屻?br> 鍥犱負鍦ㄨ皟鐢╮and()鍓嶈嚜鍔ㄨ皟鐢ㄤ簡srand(1); 榪欐潯璇彞銆?鍙湁褰搒rand()鐨勫艦鍙傛槸鍙樺寲鐨勬椂姣忔榪愯鑾峰緱鐨勯殢鏈烘暟鎵嶄笉鍚屻?br> 鐢ㄤ粈涔堟牱鐨勯殢鏃跺彉鍖栫殑鍙傛暟鍛紵 鐢╰ime(NULL), 鍗硈rand((unsigned)time(NULL)); rand(); 榪欐牱姣忔榪愯寰楀埌鐨勯殢鏈烘暟涓嶅悓銆?br> 濡備綍鑾峰緱鏌愪釜鍖洪棿鐨勯殢鏈烘暟錛?br> ---- 濡傛灉鏄尯闂碵0,n), rand()%n 灝卞彲浠ヤ簡 ---- 濡傛灉鏄尯闂碵m,n), rand()%n+m 灝卞彲浠ヤ簡 ----濡傛灉鏄尯[0,1), rand()/double(RAND_MAX) 灝卞彲浠ュ彲浠ヤ簡銆?RAND_MAX鍦╟stdlib閲屾湁瀹氫箟) 榪欓噷鏈夋洿璇︾粏鐨勪粙緇嶏細http://blog.csdn.net/zhoubl668/archive/2009/01/04/3704604.aspx
]]> 綾繪垚鍛樺嚱鏁扮戶鎵匡紙virtual銆侀潪virtual錛?/title> http://m.shnenglu.com/liyuxia713/archive/2010/01/08/105170.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Fri, 08 Jan 2010 08:30:00 GMT http://m.shnenglu.com/liyuxia713/archive/2010/01/08/105170.html http://m.shnenglu.com/liyuxia713/comments/105170.html http://m.shnenglu.com/liyuxia713/archive/2010/01/08/105170.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/105170.html http://m.shnenglu.com/liyuxia713/services/trackbacks/105170.html 鈽?瀵逛簬鐖剁被鍑芥暟錛坴irtual銆侀潪virtual錛夛紝濡傛灉瀛愮被娌℃湁鍚屽悕鍑芥暟錛屽垯姝e父緇ф壙
鈽?瀵逛簬鐖剁被鍑芥暟錛坴irtual銆侀潪virtual錛夛紝濡傛灉瀛愮被鏈夊悓鍚嶅嚱鏁幫紝鏃犲悓鍨嬪嚱鏁幫紝鍒欎笉鑳借皟鐢ㄧ埗綾誨嚱鏁?
鈽?瀵逛簬鐖剁被鍑芥暟錛坴irtual銆侀潪virtual錛夛紝濡傛灉鏈夊悓鍨嬪嚱鏁幫細
----闈瀡irtual鍑芥暟鐢辨寚閽堢被鍨嬪喅瀹氳皟鐢ㄥ摢涓?
----virtual鍑芥暟鐢辨寚閽堟寚鍚戠殑瀵硅薄鍐沖畾璋冪敤鍝釜錛堣繍琛屾椂鍐沖畾錛? 闃呰鍏ㄦ枃 ]]> 綾籹tatic鎴愬憳 http://m.shnenglu.com/liyuxia713/archive/2010/01/08/105152.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Fri, 08 Jan 2010 04:22:00 GMT http://m.shnenglu.com/liyuxia713/archive/2010/01/08/105152.html http://m.shnenglu.com/liyuxia713/comments/105152.html http://m.shnenglu.com/liyuxia713/archive/2010/01/08/105152.html#Feedback 6 http://m.shnenglu.com/liyuxia713/comments/commentRss/105152.html http://m.shnenglu.com/liyuxia713/services/trackbacks/105152.html 綾?/span>static 鎴愬憳寮曡繘錛氭湁鏃剁壒瀹氱被鐨勫叏浣撳璞¢渶瑕佽闂竴涓叏灞瀵硅薄銆?/span>
鈽?/span>涓轟粈涔堢敤 static 鎴愬憳鑰屼笉鏄叏灞瀵硅薄錛?/span>
---- static瀵硅薄鍚嶅瓧鍦ㄧ被浣滅敤鍩熶腑錛屽彲浠ユ湁鏁堥伩鍏嶅懡鍚嶅啿紿侊紝騫朵笖娓呮櫚鏄劇ず紼嬪簭鎰忓浘銆?/span>
---- 鍙互瀹炴柦灝佽錛?/span>static 鎴愬憳鍙互瀹氫箟涓?/span>private 錛岃屽叏灞瀵硅薄涓嶅彲浠ワ級
鈽?/span> 濡備綍璋冪敤錛?/span> ---- class A a; A::static_mem; a.static_mem;
鈽?/span> 澹版槑鍜屽畾涔?/span>
---- static鎴愬憳鍑芥暟鍦ㄧ被瀹氫箟浣撳唴閮ㄥ閮ㄥ畾涔夊潎鍙傚湪綾誨畾涔変綋澶栧畾涔夋椂涓嶅姞錛堜笉鍙互鍔狅級 static 淇グ銆?/span>
---- static鏁版嵁鎴愬憳蹇呴』鍦ㄧ被瀹氫箟浣撳閮ㄥ畾涔夛紙姝eソ涓嬈★級 ( 鍦ㄧ被瀹氫箟浣撳澹版槑騫跺畾涔?/span>)
class A{public : static int n;} int A::n = 10;
---- const static鏁版嵁鎴愬憳鍙互錛堜篃鍙互涓嶏級鍦ㄧ被瀹氫箟鍐呭垵濮嬪寲錛屼絾蹇呴』鍦ㄧ被瀹氫箟浣撳閮ㄩ噸鏂板0鏄庯紙涓嶅彲浠ュ姞 static 淇グ絎︼紝涓嶅彲浠ヨ祴鍒濆鹼級
鈽?/span> static 鏁版嵁鎴愬憳鍏朵粬鐗規э細
----涓鑸湴錛屽湪綾葷殑鍐呴儴涓嶈兘鏈夎綾葷被鍨嬬殑鍙橀噺錛堟垨鍑芥暟褰㈠弬錛夛紝鏈澶氬彧鑳芥湁璇ョ被綾誨瀷鐨勬寚閽堟垨寮曠敤鍋氬彉閲忕被鍨嬶紙鎴栧嚱鏁板艦鍙傦級 . static 鏁版嵁鎴愬憳鍒欎笉鍙楄繖涓檺鍒躲?/span>
---- 綾葷殑 static 鏁版嵁鎴愬憳鍙互浣滀負鍑芥暟榛樿瀹炲弬 ---- static鎴愬憳鐨勭戶鎵匡細濡傛灉鍩虹被鏈塻tatic鎴愬憳錛屽垯鏁翠釜緇ф壙灞傛涓彧鏈変竴涓繖鏍風殑鎴愬憳銆傛瘡涓猻tatic鎴愬憳鎬繪槸鍙湁涓涓疄渚嬨?br>
1 #include < iostream > 2 #include < cstdlib > 3 4 using namespace std; 5 6 class A 7 { 8 // 閲嶈澆杈撳嚭鎿嶄綔絎?nbsp; 9 friend ostream & operator << (ostream & out , const A & a) 10 { 11 out << a.m; 12 return out ; 13 }14 15 private : 16 int m ; 17 18 public : 19 A(int i) { m = i;} 20 21 static int n; 22 23 static A a; // 綾誨彲浠ユ湁璇ョ被綾誨瀷鐨剆tatic鎴愬憳 24 // A a1; // error. 綾諱笉鍙互鏈夋櫘閫氱殑璇ョ被綾誨瀷鐨勬垚鍛?nbsp; 25 26 static void func(A a) {cout << a << endl;} // 綾葷被鍨嬪彲浠ヤ綔涓鴻綾籹tatic鍑芥暟鐨勫艦鍙?nbsp; 27 28 // static 鏁版嵁鎴愬憳鍙互浣滀負綾繪垚鍛樺嚱鏁扮殑榛樿瀹炲弬 29 static void func2( int i = n) { cout << i * i << endl;} 30 }; 31 32 int A::n = 10 ; 33 A A::a(1 ); 34 35 int main() 36 { 37 cout << A::n << endl; // 10 38 cout << A::a << endl; // 1 39 40 A a2(3 ); 41 A::func(a2); // 3 42 A::func2(); // 100 43 44 system(" pause " ); 45 return 0 ; 46 }
]]> 娣卞叆鐞嗚Вstrcpy錛宻trncpy http://m.shnenglu.com/liyuxia713/archive/2009/04/26/81155.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 26 Apr 2009 12:59:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/04/26/81155.html http://m.shnenglu.com/liyuxia713/comments/81155.html http://m.shnenglu.com/liyuxia713/archive/2009/04/26/81155.html#Feedback 1 http://m.shnenglu.com/liyuxia713/comments/commentRss/81155.html http://m.shnenglu.com/liyuxia713/services/trackbacks/81155.html 闃呰鍏ㄦ枃 ]]> sizeof錛氾紙鍚綅鍩燂級緇撴瀯浣撳唴瀛樺榻愶紝鍘嬬緝瀛樺偍 http://m.shnenglu.com/liyuxia713/archive/2009/04/25/80918.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sat, 25 Apr 2009 03:33:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/04/25/80918.html http://m.shnenglu.com/liyuxia713/comments/80918.html http://m.shnenglu.com/liyuxia713/archive/2009/04/25/80918.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/80918.html http://m.shnenglu.com/liyuxia713/services/trackbacks/80918.html 1. 涓浜涘熀鏈被鍨嬬殑vc6 sizeof緇撴灉
2. 緇撴瀯浣撶殑鍐呭瓨瀵歸綈
3. 鍚綅鍩熺殑緇撴瀯浣撲粙緇? 4. 鍚綅鍩熺殑緇撴瀯浣撶殑鍐呭瓨瀵歸綈錛堝帇緙╁瓨鍌ㄥ拰闈炲帇緙╁瓨鍌級
5. 宓屽緇撴瀯浣撶殑sizeof
6. 綾誨璞$殑sizeof
7. 閫氳繃浠g爜濡備綍淇敼榛樿瀵歸綈妯℃暟 闃呰鍏ㄦ枃 ]]> [瀵煎叆]澶氶噸緇ф壙涓庤櫄緇ф壙 http://m.shnenglu.com/liyuxia713/archive/2009/03/25/79747.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Wed, 25 Mar 2009 08:20:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/03/25/79747.html http://m.shnenglu.com/liyuxia713/comments/79747.html http://m.shnenglu.com/liyuxia713/archive/2009/03/25/79747.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/79747.html http://m.shnenglu.com/liyuxia713/services/trackbacks/79747.html Technorati 鏍囩: 澶氶噸緇ф壙錛岃櫄緇ф壙
1.澶氶噸緇ф壙涓嬬殑綾諱綔鐢ㄥ煙鍚嶅瓧鏌ユ壘瑙勫垯錛?/strong>絎竴姝ワ紝緙栬瘧鍣ㄦ壘鍒頒竴涓尮閰嶇殑澹版槑銆傚鏋滃尮閰嶇殑澹版槑涓嶆涓涓紝鍒欏鑷翠簩涔夋э紝鍑洪敊錛涚浜屾錛岀紪璇戝櫒紜畾鎵懼埌鐨勫悕瀛楁槸鍚﹀悎娉曘?
閬垮厤浜屼箟鎬х殑鏂規硶錛氬湪瑙e喅浜屼箟鎬х殑媧劇敓綾諱腑瀹氫箟鍑芥暟鐨勪竴涓増鏈?
2. 閲囩敤铏氱戶鎵跨殑鏂規硶鍙互鏈夋晥鍑忓皯浜屼箟鎬с?/strong>瀹氫箟铏氱戶鎵跨殑鏂規硶錛屽湪媧劇敓鍒楄〃涓寘鍚?#8220;virtual”銆?
铏氱戶鎵夸腑鍚嶅瓧鏌ユ壘鏂規硶銆傝鏌ユ壘鍑芥暟func錛氾紙1錛夊鏋滃湪姣忎釜璺緞涓璮unc琛ㄧず鍚屼竴鍩虹被鎴愬憳錛屽垯娌℃湁浜屼箟鎬э紝鍥犱負綾誨叡浜鎴愬憳鐨勫崟涓疄渚嬨傦紙2錛夊鏋滃湪鏌愪釜璺緞涓璮unc鏄櫄鍩虹被鐨勬垚鍛橈紝鑰屽湪鍙︿竴璺緞涓婃槸鍚庝唬媧劇敓綾葷殑鎴愬憳錛屼篃娌℃湁浜屼箟鎬э紝鍥犱負鐗瑰畾媧劇敓綾誨疄渚嬬殑浼樺厛綰ч珮浜庡叡浜櫄鍩虹被瀹炰緥銆傦紙3錛夊鏋滄部姣忎釜緇ф壙璺緞func琛ㄧず鍚庝唬媧劇敓綾葷殑涓嶅悓鎴愬憳錛屽垯鍏鋒湁浜屼箟鎬с?
3.铏氱戶鎵跨殑鐗規畩鍒濆鍖栨柟寮?/strong>銆傞氬父錛屾瘡涓被鍙垵濮嬪寲鑷繁鐨勭洿鎺ュ熀綾匯備絾鍦ㄨ櫄緇ф壙涓篃榪欐牱榪愯鐨勮瘽錛屽彲鑳戒細澶氭鍒濆鍖栬櫄鍩虹被銆?
鐢辨渶浣庡眰錛堥潪铏氱戶鎵匡級媧劇敓綾葷殑鏋勯犲嚱鏁板垵濮嬪寲铏氬熀綾匯傦紙2錛変換浣曠洿鎺ユ垨闂存帴緇ф壙铏氬熀綾葷殑綾諱竴鑸篃蹇呴』涓鴻铏氬熀綾繪彁渚涜嚜宸辯殑鍒濆鍖栧紡錛屼互鎻愪緵鑷韓瀵硅薄鍒濆鍖栦嬌鐢ㄣ?
class ZooAnimal{...};
class Bear: public virtual ZooAnimal{...};
class Raccoon: public virtual ZooAnimal{...};
class Endangered{...};
class Panda: public Bear,public Raccoon,public Endangered{...};
鍦ㄤ笂闈㈢殑渚嬪瓙涓紝Panda鏋勯犲嚱鏁板垵濮嬪寲Panda錛孼ooAnimal,Bear,Raccoon,Endangered閮ㄥ垎錛屼緵Panda瀵硅薄浣跨敤銆侭ear錛坥r Raccoon錛夋瀯閫犲嚱鏁板垵濮嬪寲Bear(or Raccoon),ZooAnimal閮ㄥ垎渚汢ear(or Raccoon)瀵硅薄浣跨敤.
4. 铏氱戶鎵跨殑鏋勯犲嚱鏁版搴?/strong>銆傚厛鏄叏閮ㄧ洿鎺ュ熀綾葷殑铏氬熀綾葷殑鏋勯犲嚱鏁版寜澹版槑鐨勯『搴忥紝鐒跺悗鏄潪铏氬熀綾誨嚱鏁版寜澹版槑鐨勯『搴忚繍琛屻?img height=1 alt="" src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=982263437555584821&page=RSS%ef%bc%9a%e5%a4%9a%e9%87%8d%e7%bb%a7%e6%89%bf%e4%b8%8e%e8%99%9a%e7%bb%a7%e6%89%bf&referrer=" width=1 border=0> 鏂囩珷鏉ユ簮:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!267.entry
]]>
[瀵煎叆]妯℃澘涓殑涓浜涜鍒?/title> http://m.shnenglu.com/liyuxia713/archive/2009/03/25/79748.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Wed, 25 Mar 2009 06:56:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/03/25/79748.html http://m.shnenglu.com/liyuxia713/comments/79748.html http://m.shnenglu.com/liyuxia713/archive/2009/03/25/79748.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/79748.html http://m.shnenglu.com/liyuxia713/services/trackbacks/79748.html 1. 妯℃澘瀹氫箟鍐呯殑鑷畾涔夌被鍨嬫垚鍛樿皟鐢ㄦ柟娉曪紙鐢╰ypename鏄劇ず璇存槑錛夛細 綾誨彲浠ュ畾涔夌被鍨嬫垚鍛橈紝濡俿ize_type, size_t絳夌被鍨嬨傚湪瀹氫箟妯℃澘綾繪椂濡備綍璋冪敤瀹冨憿錛熶負浜嗚鏄庢槸綾誨瀷錛屾樉紺虹敤typename璇存槑銆?
template<class cl, class T>
cl func(cl* cl_p, T value)
{
//cl::size_type * value; // If cl::size_type is a type, then a declaration
// If cl::size_type is an object, then a multiplication
typename cl::size_type *value;
}
2. 闈炵被鍨嬫ā鏉垮艦鍙傜殑浣跨敤: 妯℃澘闈炵被鍨嬪艦鍙傛槸妯℃澘瀹氫箟鍐呴儴鐨勫父閲忓?(鍦ㄩ渶瑕佸父閲忚〃杈懼紡鐨勬椂鍊?鍙互鐢ㄩ潪綾誨瀷褰㈠弬,濡傚畾涔夋暟緇勭殑闀垮害)銆?
鍥犱負闈炵被鍨嬫ā鏉垮艦鍙傞渶瑕佷紶閫掔殑鏄父閲忚〃杈懼紡錛屾墍浠ヤ笉鏀寔涓鑸殑闅愬紡綾誨瀷杞崲銆?
template<class T, size_t N> void fcn(T (&cl)[N]) {...}
int x[20];
fcn(x);
3. 妯℃澘浣曟椂瀹炰緥鍖栵紵 鍑芥暟澹版槑錛屽畾涔夊璞$殑寮曠敤鍜屾寚鍚戝璞$殑鎸囬拡閮戒笉浼氬疄渚嬪寲銆傚畾涔夌被瀵硅薄鎴栬皟鐢ㄥ嚱鏁版椂瀹炰緥鍖栥?
4.friend妯℃澘澹版槑渚濊禆鎬э細 錛?錛?褰撴巿浜堝緇欏畾妯℃澘鎵鏈夊疄渚嬬殑璁塊棶鏉冩椂錛屽湪浣滅敤鍩熶腑涓嶉渶瑕佸瓨鍦ㄨ綾繪ā鏉挎垨鍑芥暟妯℃澘鐨勫0鏄庛傜紪璇戝櫒灝嗗弸鍏冨0鏄庝篃褰撲綔綾繪垨鍑芥暟鐨勫0鏄庡寰咃紱錛?錛夋兂瑕侀檺鍒跺鐗瑰畾瀹炰緥鍖栫殑鍙嬪厓鍏崇郴鏃訛紝蹇呴』鍦ㄥ彲浠ョ敤浜庡弸鍏冨0鏄庝箣鍓嶅0鏄庣被鎴栧嚱鏁般?
5.瀵逛簬涓嶅悓鍙傛暟鐨勫嚱鏁版ā鏉跨敤鐩稿悓鍙傛暟鍙互璋冪敤涔堬紵 鍙互錛屼細璋冪敤闅愬紡杞崲銆?
#include<iostream>
using namespace std;
template<typename T1, typename T2>
void print(const T1 &v1, const T2 &v2) //鍙傛暟綾誨瀷涓嶅悓 { cout << "T1 = " << v1 <<endl; cout << "T2 = " << v2 <<endl; }
int main() { print(1,2); //ok
int a=1; int b=2; print(a,b); //ok錛屽艦鍙傜被鍨嬬浉鍚?/font>
return 0; } 鏂囩珷鏉ユ簮:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!266.entry
]]>
[瀵煎叆]妯℃澘緙栬瘧妯″瀷 http://m.shnenglu.com/liyuxia713/archive/2009/03/24/79749.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Tue, 24 Mar 2009 07:50:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/03/24/79749.html http://m.shnenglu.com/liyuxia713/comments/79749.html http://m.shnenglu.com/liyuxia713/archive/2009/03/24/79749.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/79749.html http://m.shnenglu.com/liyuxia713/services/trackbacks/79749.html 1.鍖呭惈緙栬瘧妯″瀷錛坕nclusion compilation model錛? 鍑芥暟澹版槑鏀懼湪澶存枃浠朵腑錛屽畾涔夋斁鍦ㄦ簮鏂囦歡涓傚ご鏂囦歡灝懼寘鍚簮鏂囦歡銆傛嵁璇翠細鍑虹幇涓涓ā鏉垮疄渚嬪寲澶氭浠庤屽鑷寸紪璇戞椂鎬ц兘鏄捐憲闄嶄綆銆?
//template.cpp template<typename T> void print(const T &v) { cout << "T = " << v <<endl; }
//template.h #ifndef TEMPLATE_H #define TEMPLATE_H
template<typename T> void print(const T &v);
#include "template.cpp"
#endif
//main.cpp #include<iostream> #include "template.h" //#include"template.cpp" 鐢ㄨ繖鏉″懡浠や唬鏇夸篃鍙互銆?/font>
using namespace std;
int main() { print(1); //ok return 0; }
2. 鍒嗗埆緙栬瘧妯″瀷錛坰eperate compilation model錛?鍑芥暟澹版槑鍜岀被瀹氫箟鏀懼湪澶存枃浠朵腑錛屽甫export鍏抽敭瀛楃殑鍑芥暟瀹氫箟鍜岀被澹版槑鏀懼湪婧愭枃浠朵腑銆傛簮鏂囦歡灝懼寘鍚ご鏂囦歡銆傦紙涓嶇煡閬撶悊瑙g殑瀵逛笉瀵癸紝鐢ㄧ殑緙栬瘧鍣ㄤ笉鏀寔鍒嗗埆緙栬瘧錛屾殏鏃舵棤浠庡垽鏂簡 錛?
//the template definition goes in a separately-compiled source file
export template<typename T>
T print(const T&v) /*...*/
//class template header goes in shared header file
template <class T> class cl{...};
//cl.cpp implementation file declares cl as exported
export template <class T> class cl;
#include "cl.h"
//cl member definitions
鏂囩珷鏉ユ簮:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!265.entry
]]>
[瀵煎叆]鍩虹被鐨勫鍒舵帶鍒跺嚱鏁?/title> http://m.shnenglu.com/liyuxia713/archive/2009/03/23/79750.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Mon, 23 Mar 2009 11:09:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/03/23/79750.html http://m.shnenglu.com/liyuxia713/comments/79750.html http://m.shnenglu.com/liyuxia713/archive/2009/03/23/79750.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/79750.html http://m.shnenglu.com/liyuxia713/services/trackbacks/79750.html 鏋勯犲嚱鏁頒笉鑳藉畾涔変負virtual錛屾淳鐢熺被瀵硅薄鐨勫熀綾繪暟鎹垚鍛橀儴鍒嗗湪鍒濆鍖栧垪琛ㄤ腑鐢ㄥ熀綾繪瀯閫犲嚱鏁板垵濮嬪寲錛?
鍩虹被鏋愭瀯鍑芥暟搴斿畾涔変負virtual錛屽鍒舵搷浣滅涓鑸畾涔変負闈瀡irtual
鍦ㄥ熀綾繪瀯閫犲嚱鏁板拰鏋愭瀯鍑芥暟涓紝灝嗘淳鐢熺被瀵硅薄褰撲綔鍩虹被綾誨瀷瀵硅薄瀵瑰緟銆傦紙鍥犱負鍦ㄨ繖涓や釜鍑芥暟鐨勮繍琛岃繃紼嬩腑錛屽璞′笉鏄竴涓畬鏁寸殑媧劇敓綾葷被鍨嬶級
綾葷殑澶嶅埗鎺у埗鐨勪笁娉曞垯鏈変釜渚嬪錛氬畾涔夛紙絀猴級铏氭瀯澶熷嚱鏁版椂鍙互涓嶅畾涔夋瀯閫犲嚱鏁板拰璧嬪煎嚱鏁般?img height=1 alt="" src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=982263437555584821&page=RSS%ef%bc%9a%e5%9f%ba%e7%b1%bb%e7%9a%84%e5%a4%8d%e5%88%b6%e6%8e%a7%e5%88%b6%e5%87%bd%e6%95%b0&referrer=" width=1 border=0> 鏂囩珷鏉ユ簮:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!264.entry
]]> [瀵煎叆]媧劇敓綾誨埌鍩虹被杞崲鐨勫彲璁塊棶鎬?/title> http://m.shnenglu.com/liyuxia713/archive/2009/03/22/79751.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 22 Mar 2009 12:22:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/03/22/79751.html http://m.shnenglu.com/liyuxia713/comments/79751.html http://m.shnenglu.com/liyuxia713/archive/2009/03/22/79751.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/79751.html http://m.shnenglu.com/liyuxia713/services/trackbacks/79751.html 媧劇敓綾繪湰韜殑鎴愬憳鍜屽弸鍏冧換浣曠戶鎵挎椂閮藉彲浠ヤ嬌鐢ㄦ淳鐢熺被鍒板熀綾昏漿鎹€?
瀵逛簬鍚庝唬綾誨拰鐢ㄦ埛浠g爜錛?
public緇ф壙鏃訛細鍚庝唬綾誨拰鐢ㄦ埛浠g爜閮藉彲浠ャ?
protected緇ф壙鏃訛細鍚庝唬綾誨彲浠ワ紝鐢ㄦ埛浠g爜涓嶅彲浠ャ?
private緇ф壙鏃訛細鍚庝唬綾誨拰鐢ㄦ埛浠g爜閮戒笉鍙互銆?img height=1 alt="" src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=982263437555584821&page=RSS%ef%bc%9a%e6%b4%be%e7%94%9f%e7%b1%bb%e5%88%b0%e5%9f%ba%e7%b1%bb%e8%bd%ac%e6%8d%a2%e7%9a%84%e5%8f%af%e8%ae%bf%e9%97%ae%e6%80%a7&referrer=" width=1 border=0> 鏂囩珷鏉ユ簮:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!263.entry
]]> [瀵煎叆]媧劇敓綾誨鍩虹被鎴愬憳鐨勮闂潈闄?/title> http://m.shnenglu.com/liyuxia713/archive/2009/03/22/79752.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 22 Mar 2009 11:26:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/03/22/79752.html http://m.shnenglu.com/liyuxia713/comments/79752.html http://m.shnenglu.com/liyuxia713/archive/2009/03/22/79752.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/79752.html http://m.shnenglu.com/liyuxia713/services/trackbacks/79752.html 1.媧劇敓綾誨鍩虹被private鎴愬憳娌℃湁璁塊棶鏉冮檺銆?
2.媧劇敓綾誨彧鑳介氳繃媧劇敓綾誨璞¤闂叾鍩虹被鐨刾rotected鎴愬憳 錛屾淳鐢熺被瀵瑰叾鍩虹被綾誨瀷瀵硅薄鐨刾rotected鎴愬憳 娌℃湁鐗規畩璁塊棶鏉冮檺銆?
#include<iostream> using namespace std;
class Base { public: Base():i(0),j(0){}; protected: int i; private: int j; };
class Derived:public Base { Derived():Base(){};
print(const Base &b, const Derived &d) { int num = i; //num = b.i; //error. cannot access protected member declared in class 'Base' num = d.i; //num = d.j; //error. cannot access private member declared in class 'Base' }; };
int main() { return 0; } 鏂囩珷鏉ユ簮:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!262.entry
]]> [瀵煎叆]鏋愭瀯鍑芥暟錛堝唴瀛樻硠婕忥紝涓夋硶鍒欙級 http://m.shnenglu.com/liyuxia713/archive/2009/03/08/79754.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 08 Mar 2009 13:25:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/03/08/79754.html http://m.shnenglu.com/liyuxia713/comments/79754.html http://m.shnenglu.com/liyuxia713/archive/2009/03/08/79754.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/79754.html http://m.shnenglu.com/liyuxia713/services/trackbacks/79754.html Technorati 鏍囩: 鏋愭瀯鍑芥暟錛屽唴瀛樻硠婕忥紝涓夋硶鍒?/a>
浠諱綍鏃跺欑紪璇戝櫒閮戒細鍚堟垚鏋愭瀯鍑芥暟錛屽茍涓斿悎鎴愮殑鏋愭瀯鍑芥暟鎬諱細榪愯銆?
鎾ら攢瀹瑰櫒錛堟爣鍑嗗簱瀹瑰櫒鍜屽唴緗暟緇勶級鏄寜閫嗗簭榪涜鐨勩?
鍐呭瓨娉勬紡錛圡emory leak錛夛細 鍒犻櫎鎸囧悜鍔ㄦ佸垎閰嶅唴瀛樼殑鎸囬拡澶辮觸錛屽洜鑰屾棤娉曞皢璇ュ潡鍐呭瓨榪旇繕緇欒嚜鐢卞瓨鍌ㄥ尯錛岃繖鏍風殑鍒犻櫎鍔ㄦ佸垎閰嶅唴瀛樺け璐ョО涓哄唴瀛樻硠婕忋?/font>
鍙湁褰撳垹闄ゆ寚鍚戠被瀵硅薄鐨勬寚閽堟椂鎵嶄細榪愯璇ュ璞$殑鏋愭瀯鍑芥暟銆傚鏋滀笉鍒犻櫎鎸囬拡錛屽垯瀵硅薄涓鐩村瓨鍦紝瀵艱嚧鍐呭瓨娉勬紡銆?
涓夋硶鍒欙紙rule of three錛夛細 濡傛灉綾婚渶瑕佹瀽鏋勫嚱鏁幫紝鍒欎篃闇瑕佽祴鍊兼搷浣滅鍜屽鍒舵瀯閫犲嚱鏁般?img height=1 alt="" src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=982263437555584821&page=RSS%ef%bc%9a%e6%9e%90%e6%9e%84%e5%87%bd%e6%95%b0%ef%bc%88%e5%86%85%e5%ad%98%e6%b3%84%e6%bc%8f%ef%bc%8c%e4%b8%89%e6%b3%95%e5%88%99%ef%bc%89&referrer=" width=1 border=0> 鏂囩珷鏉ユ簮:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!255.entry
]]>
[瀵煎叆]錛堝鍒躲侀粯璁わ級鏋勯犲嚱鏁?/title> http://m.shnenglu.com/liyuxia713/archive/2009/03/08/79755.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 08 Mar 2009 13:00:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/03/08/79755.html http://m.shnenglu.com/liyuxia713/comments/79755.html http://m.shnenglu.com/liyuxia713/archive/2009/03/08/79755.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/79755.html http://m.shnenglu.com/liyuxia713/services/trackbacks/79755.html Technorati 鏍囩: 綾誨垵濮嬪寲鍒楄〃錛岄粯璁ゆ瀯閫犲嚱鏁幫紝澶嶅埗鏋勯犲嚱鏁?/a>
鍒濆鍖栧垪琛細 閫氬父浣跨敤鍒濆鍖栨槸涓轟簡鎻愰珮鏁堢巼錛屽畠鐩存帴璋冪敤涓庡疄鍙傚尮閰嶇殑鏋勯犲嚱鏁般傘愬洜涓轟竴鑸湪鏋勯犲嚱鏁頒綋鍐呯殑澶嶅埗涔熺粡榪囧垵濮嬪寲-->璁$畻璧嬪?font color=#404040>錛堟鏃朵細璋冪敤澶嶅埗鏋勯犲嚱鏁幫級涓や釜闃舵銆戯紱鐗瑰埆鐨勬湁浜涙椂鍊欏彧鑳界敤鍒濆鍖栧垪琛紝鍗充笉鑳借祴鍊肩殑鍙傛暟錛屽錛歝onst鎴栧紩鐢ㄧ被鍨嬬殑鎴愬憳錛屾病鏈夐粯璁ゆ瀯閫犲嚱鏁扮殑綾葷被鍨嬫垚鍛樸傚垵濮嬪寲鍒楄〃涓彉閲忕殑鍒濆鍖栭『搴忔槸鍏堝0鏄庣殑鍏堝垵濮嬪寲.
class cl1{ private: const int ci; int &ri;}; //ci,ri鍙兘鍦ㄥ垵濮嬪寲鍒楄〃涓繘琛屽垵濮嬪寲銆?/font>
榛樿鏋勯犲嚱鏁幫細 鍏ㄩ儴褰㈠弬鏄粯璁ゅ疄鍙傜殑鏋勯犲嚱鏁頒篃鏄粯璁ゆ瀯閫犲嚱鏁般?/font>
鍙鑷繁瀹氫箟浜嗭紙浠繪剰鐨勶級鏋勯犲嚱鏁幫紝緙栬瘧鍣ㄥ氨涓嶄細涓烘垜浠悎鎴愰粯璁ゆ瀯閫犲嚱鏁般?
澶嶅埗鏋勯犲嚱鏁幫細 鍗曚釜褰㈠弬涓烘湰綾葷被鍨嬪璞$殑寮曠敤鐨勬瀯閫犲嚱鏁般傚浜庝笉鏀寔澶嶅埗鐨勭被鍨嬶紙濡侷O綾誨瀷錛変笉鑳界敤澶嶅埗鏋勯犲嚱鏁般傚鏋滆嚜宸卞畾涔変簡澶嶅埗鏋勯犲嚱鏁幫紙鑰屼笉鏄瀯閫犲嚱鏁幫紝鍗籌細鍙畾涔夋瀯閫犲嚱鏁幫紝浣嗘病鏈夊畾涔夊鍒舵瀯閫犲嚱鏁幫紝鍒欑紪璇戝櫒鍚堟垚澶嶅埗鏋勯犲嚱鏁幫級錛屽垯緙栬瘧鍣ㄤ笉浼氬悎鎴愬鍒舵瀯閫犲嚱鏁般傘愬鍒舵瀯閫犲嚱鏁伴渶瑕佺壒鍒敞鎰忔寚閽堟垚鍛橈紝浠ュ悗灝嗚鏄庛?/font>
ifstream file1("filename1"); //ok, direct initialization.
ifstream file2="filename2"; //error
濡備綍闃叉澶嶅埗錛?/font>鍙互閫氳繃灝嗗鍒舵瀯閫犲嚱鏁板0鏄庝負private鏉ョ姝㈡櫘閫氬嚱鏁幫紙闈炴垚鍛橈紝闈炲弸鍏冨嚱鏁幫級鐨勮闂紱鍙互閫氳繃澹版槑涓涓猵rivate澶嶅埗鏋勯犲嚱鏁拌屼笉瀵瑰叾瀹氫箟鏉ョ姝㈡垚鍛樺嚱鏁板拰鍙嬪厓鍑芥暟鐨勮闂?img height=1 alt="" src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=982263437555584821&page=RSS%ef%bc%9a%ef%bc%88%e5%a4%8d%e5%88%b6%e3%80%81%e9%bb%98%e8%ae%a4%ef%bc%89%e6%9e%84%e9%80%a0%e5%87%bd%e6%95%b0&referrer=" width=1 border=0> 鏂囩珷鏉ユ簮:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!254.entry
]]>
[瀵煎叆]綾葷殑涓浜涚壒孌婇檺鍒舵垚鍛?/title> http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79756.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Fri, 06 Mar 2009 13:57:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79756.html http://m.shnenglu.com/liyuxia713/comments/79756.html http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79756.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/79756.html http://m.shnenglu.com/liyuxia713/services/trackbacks/79756.html inline鎴愬憳鍑芥暟錛?/font> 澹版槑鎴栧畾涔夋椂鎸囧畾涓篿nline閮藉彲浠ャ備綔鐢細鍦ㄨ皟鐢ㄥ鐩存帴鍦ㄨ鍐呭睍寮浠g爜錛屼互鎻愰珮鏁堢巼銆傜被鐨刬nline鎴愬憳鍑芥暟瀹氫箟鍦ㄥ寘鍚綾葷殑澶存枃浠朵腑銆?綾誨唴閮ㄥ畾涔夌殑鍑芥暟鍧囦負inline鍑芥暟銆?
mutable鏁版嵁鎴愬憳 錛氫換浣曞嚱鏁幫紙鍖呮嫭綾籧onst鎴愬憳鍑芥暟錛夐兘鍙互淇敼mutable鏁版嵁鎴愬憳銆?
explicit鏋勯犲嚱鏁幫細 澹版槑鏃舵寚瀹氾紝瀹氫箟鏃朵笉鍏佽閲嶅鎸囧畾涓篹xplicit銆備綔鐢細闃叉鍦ㄩ渶瑕侀殣寮忚漿鎹㈢殑涓婁笅鏂囦腑浣跨敤鏋勯犲嚱鏁般?
friend鎴愬憳錛?/font>闈炵被鎴愬憳鍙互璁塊棶綾葷殑縐佹湁鎴愬憳銆傞渶瑕佺壒鍒敞鎰忓弸鍏冨0鏄庡拰浣滅敤鍩熴傚鏋滄兂灝嗭紙鍏朵粬綾葷殑錛夋垚鍛樺嚱鏁拌涓哄弸鍏冿紝蹇呴』鍏堝0鏄庯紱鑰屽鏋滄兂灝嗭紙鍏朵粬錛夌被鎴栭潪鎴愬憳鍑芥暟璁句負鍙嬪厓錛屽垯涓嶅繀棰勫厛澹版槑銆?
static鏁版嵁鎴愬憳錛?/font>static鏁版嵁鎴愬憳涓嶇敤鏋勯犲嚱鏁幫紝鍦ㄧ被鐨勫閮ㄥ畾涔夛紝瀹氫箟鏃惰繘琛屽垵濮嬪寲銆?
static鎴愬憳鍑芥暟錛?/font>澹版槑鏃舵寚瀹歴tatic綾誨瀷錛屽畾涔夋椂涓嶇敤閲嶅澹版槑銆傛病鏈塼his鎸囬拡銆?
const static鏁版嵁鎴愬憳錛?/font>涓鑸湴綾葷殑static鏁版嵁鎴愬憳涓嶈兘鍦ㄧ被鐨勫唴閮ㄥ畾涔夈傛湁渚嬪灝辨槸鍙互鐢ㄥ父閲忚〃杈懼紡鍒濆鍖朿onst static鏁版嵁鎴愬憳錛屼笉榪囧嵆浣胯繖鏍蜂篃闇瑕佸湪綾誨畾涔変綋鐨勫閮ㄨ繘琛岃const static鏁版嵁鎴愬憳鐨勫畾涔夈?
static鎴愬憳涓嶆槸綾誨璞$殑緇勬垚閮ㄥ垎錛岄潪static鏁版嵁鎴愬憳涓嶈兘鏄鎴愬憳鎵灞炵殑綾葷被鍨嬶紝鑰屽彧鑳芥槸瀵瑰簲鐨勬寚閽堝拰寮曠敤錛岃宻tatic鎴愬憳鍒欏彲浠ユ槸璇ユ垚鍛樻墍灞炵殑綾葷被鍨嬨?/font> 鏂囩珷鏉ユ簮:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!252.entry
]]>
[瀵煎叆]瀹瑰櫒閫傞厤鍣?/title> http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79757.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Fri, 06 Mar 2009 11:17:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79757.html http://m.shnenglu.com/liyuxia713/comments/79757.html http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79757.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/79757.html http://m.shnenglu.com/liyuxia713/services/trackbacks/79757.html
queue priority_queue stack
闃熷垪 鍫?nbsp; 鏍?
deque vector deque //榛樿鐩稿叧鑱斿鍣ㄧ被鍨?/font>
push_front 闅忔満璁塊棶 鏃?nbsp; //瀵瑰叧鑱斿鍣ㄧ殑瑕佹眰
鏂囩珷鏉ユ簮:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!251.entry
]]>
[瀵煎叆]榪唬鍣?/title> http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79758.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Fri, 06 Mar 2009 11:11:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79758.html http://m.shnenglu.com/liyuxia713/comments/79758.html http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79758.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/79758.html http://m.shnenglu.com/liyuxia713/services/trackbacks/79758.html 鎰熻榪唬鍣ㄨ繖閮ㄥ垎鍑芥暟鐨勮繑鍥炵被鍨嬫槸娌″お寮勬槑鐧界殑錛屼互鍚庣敤鐨勬椂鍊欏緱澶氭敞鎰忕偣銆?
1.鎻掑叆錛?/font>涓鑸彃鍏ユ槸鍦ㄧ粰瀹氱殑榪唬鍣ㄤ綅緗墠錛岃繖鏍鋒槸end榪唬鍣ㄤ篃璇炬甯哥紪璇戙傛彃鍏ョ殑鍏冪礌綾誨瀷蹇呴』涓巆鐨勭被鍨嬪畬鍏ㄤ竴鏍楓?
void c.push_back(t);
void c.insert(p,b,e);
void c.insert(p,n,t);
iter c.insert(p,t);
2.璧嬪?/font>錛?font color=#ff00ff>c1= c2
c.assign(b,e); c.assign(n,t) //鍏佽涓嶅悓鐨勫鍣紝涓嶅悓鐨勫厓绱狅紝鍙鍏冪礌綾誨瀷鍏煎銆?/font>
3.璁塊棶錛?/font>c.back(); c.front();
c[n]; c.at[n]; //榪欐牱鐨勪笅鏍囪闂鏄撹秺鐣屻傚悗鑰呰秺鐣屾槸鎶涘嚭 out_of_range寮傚父銆?/font>
4.鍒犻櫎 錛?font color=#ff00ff>iter c.erase(p);
iter c.erase(b,e);
void c.clear();
void c.pop_back();
c.pop_front();
鏂囩珷鏉ユ簮:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!250.entry
]]>
[瀵煎叆]const闄愬埗絎?/title> http://m.shnenglu.com/liyuxia713/archive/2009/02/28/79759.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sat, 28 Feb 2009 13:38:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/02/28/79759.html http://m.shnenglu.com/liyuxia713/comments/79759.html http://m.shnenglu.com/liyuxia713/archive/2009/02/28/79759.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/79759.html http://m.shnenglu.com/liyuxia713/services/trackbacks/79759.html 1. const鍙橀噺錛?/font>const type v; 蹇呴』瀹氫箟鏃跺垵濮嬪寲錛屼笉鑳戒慨鏀瑰叾鍊箋?font color=#404040>澶囨敞錛氬叧浜巆onst鍙橀噺鐨勪綔鐢ㄥ煙瑕佺壒鍒敞鎰忥紝瀹冩槸灞閮ㄧ殑錛岃岄粯璁ょ殑C++鍙橀噺鏄叏灞鐨勩傞氳繃鍔爀xtern闄愬埗鍙互浠onst瀵硅薄鍙互鍦ㄥ叏灞琚闂傚浠g爜錛?欏轟究鎻愪竴涓媠tatic)
file1.cpp type v1;
const type v2; //now,v2 is a local variable.
extern const type v3 ;//now,v3 is a global variable. must add 'extern'~.
file2.cpp type v1; // error.redeclaration.
extern type v1; //ok.
type v2; //ok.but not equivalent to v2 in file1.cpp
const type v3; // ok.but not equivalent to v3 in file1.cpp
extern const type v3; //ok.equal to v3 in file1.cpp.
2. const寮曠敤錛?/font>const type& v; 鏄寚鍚慶onst瀵硅薄鐨勫紩鐢ㄣ傞潪const寮曠敤鍙兘緇戝畾鍒頒笌璇ュ紩鐢ㄥ悓綾誨瀷鐨勫璞°傝宑onst寮曠敤鍒欏彲浠ョ粦瀹氬埌涓嶅悓浣嗙浉鍏崇殑綾誨瀷閭d釜鐨勫璞″拰鍙沖箋?
double dv = 1.0; const int &iv = dv; 緙栬瘧鏃剁瓑浠蜂簬
int temp = dv; const int &iv = temp; //鍙互鐪嬪嚭瀵筰v鐨勪慨鏀瑰茍涓嶄細褰卞搷dv鐨勫?
3.const涓庢寚閽?/font>錛氾紙1錛?鎸囧悜const瀵硅薄鐨勬寚閽? const type* v; 鏈夋椂璁頒綔type const* v; 鍙互淇敼鎸囬拡錛屼絾涓嶈兘鐩存帴閫氳繃璇ユ寚閽堜慨鏀規寚閽堟寚鍚戠殑瀵硅薄銆傦紙鍙互閫氳繃瀹氫箟闈瀋onst鎸囬拡鎸囧悜璇ュ璞★紝浠庤屼慨鏀瑰叾鍊鹼級錛?錛?font color=#ff0000>const鎸囬拡: type *const v ;鍙互淇敼鎸囬拡鎸囧悜鐨勫璞★紝浣嗕笉鑳戒慨鏀規寚閽堟湰韜傦紙3錛?font color=#ff0000>鎸囧悜const瀵硅薄鐨刢onst鎸囬拡
錛?font color=#ff00ff>const type *const v; 錛?font color=#404040>澶囨敞錛?font color=#ff00ff>typedef string * name; const name v; //v鐨勭被鍨嬫槸鎸囧悜string綾誨瀷鐨刢onst鎸囬拡銆傦級
4.const涓庝竴鑸嚱鏁幫細 (1) const type1 func(type2 v); 鍑芥暟榪斿洖鍊間負const; (2) type1 func(const type2 v); 褰㈠弬涓篶onst鍙橀噺銆傚洜涓哄艦鍙備笉鏄紩鐢紝涓嶄慨鏀瑰疄鍙傜殑鍊鹼紝鎵浠ユ鏃剁殑const涓嶈搗鐗瑰埆鐨勪綔鐢紱錛?錛?font color=#ff00ff>type1 func(const type& v); 褰㈠弬涓篶onst寮曠敤錛屼笉淇敼浼犻掑埌褰㈠弬鐨勫疄鍙傚箋?鎸囬拡鏃剁浉鍚岋紝涓嶄慨鏀規寚閽堟寚鍚戠殑瀵硅薄鐨勫箋?
5.const涓庣被鎴愬憳鍑芥暟錛堝父閲忔垚鍛樺嚱鏁幫級 錛歵ype func(type v) const;絳変環浜巘ype func(const *this,type v) const; 瀹冩槸鍊紅his鎸囬拡鏄寚鍚慶onst瀵硅薄鐨勬寚閽堬紝榪欎釜鍑芥暟涓嶆敼鍙樿皟鐢ㄨ鍑芥暟鐨勫璞?font color=#404040>銆傦紙澶囨敞錛氫簨瀹炰笂鏄笉鍙互鏄劇ず浣跨敤this鎸囬拡浣滀負褰㈠弬鐨勶紝浣嗗彲浠ュ湪鍑芥暟浣撲腑鏄劇ず鍦頒嬌鐢╰his鎸囬拡銆傦級
6.const涓庤凱浠e櫒錛?/font>vector<type>::const_iterator it; const vector<type>::iterator iter; it鎸囧悜鐨勫厓绱犱笉鑳戒慨鏀癸紝iter鎸囧悜鐨勫厓绱犲彲浠ヤ慨鏀癸紝浣嗚凱浠e櫒鏈韓涓嶈兘淇敼銆?
7.const涓庡鍣細 const vector<type> vec; 闇瑕佹敞鎰忔鏃跺畾涔夌殑瀹瑰櫒榪唬鍣ㄥ繀欏繪槸const_iterator鍨嬨?img height=1 alt="" src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=982263437555584821&page=RSS%ef%bc%9aconst%e9%99%90%e5%88%b6%e7%ac%a6&referrer=" width=1 border=0> 鏂囩珷鏉ユ簮:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!243.entry
]]>
[瀵煎叆]鍑芥暟鍙傛暟 http://m.shnenglu.com/liyuxia713/archive/2009/02/28/79760.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sat, 28 Feb 2009 11:18:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/02/28/79760.html http://m.shnenglu.com/liyuxia713/comments/79760.html http://m.shnenglu.com/liyuxia713/archive/2009/02/28/79760.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/79760.html http://m.shnenglu.com/liyuxia713/services/trackbacks/79760.html 1.闈炲紩鐢ㄥ艦鍙?/font>閫氳繃澶嶅埗瀹炲弬鍊煎垱寤哄拰瀹氫箟鍑芥暟鐨勫眬閮ㄥ璞★紝浠庤屽褰㈠弬鐨勬搷浣滀笉鏀瑰彉瀹炲弬鍊箋傚洜涓烘槸澶嶅埗鍒濆鍖栧湪褰㈠弬鍓嶅姞const鏃犲獎鍝嶃?font color=#ff00ff>type function(type2 v) 鍜?font color=#ff00ff>type function(const type2 v) 鏄瓑浠風殑銆傝繖涓鐐瑰湪鍑芥暟閲嶈澆鏃朵篃瑕佹敞鎰忥紝濡傛灉鍚屾椂鍑虹幇涓婅堪鐨勪袱涓嚱鏁板垯鏄噸澶嶅畾涔夎屼笉鏄噸杞姐?/font>
2.寮曠敤褰㈠弬 鏄疄鍙傜殑鍒悕錛屼粠鑰屽褰㈠弬鐨勬搷浣滄敼鍙樺疄鍙傚箋傜敤閫旓細絎竴錛屽ぇ鍨嬬殑鍙傛暟閫氳繃澶嶅埗鍒濆鍖栨晥鐜囦綆鏃剁敤寮曠敤鍙傛暟錛涚浜岋紝瀵逛簬涓浜涗笉鑳藉鍒跺垵濮嬪寲鐨勫弬鏁幫紱絎笁錛屽彲浠ラ氳繃澧炲姞褰㈠弬榪斿洖棰濆鐨勪俊鎭?娉ㄦ剰錛?/font>type function(type2 v) 鍜?type function(const type2 v) 鏄笉鍚岀殑銆?/font>
3.const& :涓鑸笉闇瑕佷慨鏀瑰疄鍙傛椂鐢╟onst寮曠敤銆傝繖涓昏鏄冭檻鍒伴潪const寮曠敤褰㈠弬鐨勫涓嬬己鐐癸細絎竴錛屼紶閫掔殑瀹炲弬蹇呴』涓庡艦鍙傜被鍨嬪畬鍏ㄧ浉鍚岋紝鑰屼笉鍖呭惈鍙互闅愬紡杞崲鐨勭被鍨嬶紱絎簩錛屼紶閫掔殑瀹炲弬涓嶈兘鏄痗onst錛屽彸鍊箋?/font>
4.鎸囧悜鎸囬拡鐨勫紩鐢?/font> type* &v 錛?/font>
5.錛?)闈炲紩鐢ㄦ暟緇勫艦鍙?/font>錛?font color=#ff00ff>int*, int[],int[n]銆?/font>榪欎笁涓槸絳変環鐨勶紝閮戒紶閫掓寚鍚戠涓涓厓绱犵殑鎸囬拡銆傝繖鏍峰鏄撲駭鐢熻秺鐣屻傚浣曢槻姝㈣秺鐣屽憿錛熺涓錛岄氳繃緇撴潫鏍囪媯嫻嬫暟緇勭殑緇撴潫錛屽C椋庢牸瀛楃涓詫紱絎簩錛岀敤鏍囧噯搴撹鑼冿紝浼犻掔涓涓拰鏈鍚庝竴涓殑涓嬩竴涓厓绱犵殑鎸囬拡鍋氬弬鏁幫紱絎笁錛屾樉紺轟紶閫掓暟緇勫ぇ灝忕殑褰㈠弬銆?/font>
5.錛?錛?font color=#ff0000>寮曠敤鏁扮粍褰㈠弬 錛?font color=#ff00ff>type (&arr)[n]錛?/font> 娉ㄦ剰涓ょ偣錛氫竴鏄紝鍦嗘嫭鍙鋒槸蹇呴』鐨勶紝鍥犱負涓嬫爣榪愮畻絎︾殑浼樺厛綰ф洿楂橈紱浜屾槸錛岃〃紺烘暟緇勫厓绱犱釜鏁扮殑n鏄繀欏葷殑錛屽洜涓哄紩鐢ㄦ槸鏁扮粍鍒悕錛岃屾暟緇勬槸鍥哄畾闀垮害鐨勩?/font>
6.榛樿瀹炲弬 錛氱涓瑕佽冭檻浣嶇疆錛岀浜岋紝濡傛灉鎻愪緵瀹炲弬錛屽垯瀹冭鐩栭粯璁ょ殑瀹炲弬鍊箋?/font> 鏂囩珷鏉ユ簮:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!242.entry
]]>
[瀵煎叆]C椋庢牸瀛楃涓蹭笌string綾誨瀷 http://m.shnenglu.com/liyuxia713/archive/2009/02/27/79761.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Fri, 27 Feb 2009 13:18:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/02/27/79761.html http://m.shnenglu.com/liyuxia713/comments/79761.html http://m.shnenglu.com/liyuxia713/archive/2009/02/27/79761.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/79761.html http://m.shnenglu.com/liyuxia713/services/trackbacks/79761.html C椋庢牸瀛楃涓茬瓑浠蜂簬string 綾誨瀷瀛楃涓插瓧闈㈠?
string str1("Hello!"); //ok.
char *str2 = str1; //error.
char *str3 = str2.c_str(); //ok. but not quite.
//娉ㄦ剰c_str()榪斿洖鐨勬暟鎹被鍨嬫槸const char
const char *str4 = str2.c_str(); //ok. 鏂囩珷鏉ユ簮:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!232.entry
]]> [瀵煎叆]鍔ㄦ佸唴瀛樼鐞?/title> http://m.shnenglu.com/liyuxia713/archive/2009/02/27/79762.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Fri, 27 Feb 2009 13:09:00 GMT http://m.shnenglu.com/liyuxia713/archive/2009/02/27/79762.html http://m.shnenglu.com/liyuxia713/comments/79762.html http://m.shnenglu.com/liyuxia713/archive/2009/02/27/79762.html#Feedback 0 http://m.shnenglu.com/liyuxia713/comments/commentRss/79762.html http://m.shnenglu.com/liyuxia713/services/trackbacks/79762.html 鍔ㄦ佸垎閰嶇殑鏁扮粍錛?/font> 鎴愬憳涓虹被綾誨瀷鏃剁敤榛樿鏋勯犲嚱鏁幫紝涓哄唴緗被鍨嬫椂涓嶈嚜鍔ㄥ垵濮嬪寲銆傦紙鍚屽嚱鏁板唴閮ㄥ彉閲忕殑鑷姩鍒濆鍖栵級
鍙互閲囩敤 new type[]() 鐢卞唴緗被鍨嬬殑榛樿鍊煎垵濮嬪寲錛屾敞鎰忎笉鑳藉湪鍦嗘嫭鍙峰唴鍐欏叆鍊煎垵濮嬪寲銆?
浣嗘槸褰撴槸鍗曚釜瀵硅薄瀹氫箟鏃跺彲浠ワ細 new type(value) 鏄湁鏁堢殑 鏂囩珷鏉ユ簮:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!231.entry
]]>
久久99毛片免费观看不卡 |
日韩精品久久久久久久电影 |
久久福利青草精品资源站 |
国产亚洲欧美成人久久片 |
久久久久久青草大香综合精品 |
久久亚洲sm情趣捆绑调教 |
99久久er这里只有精品18 |
久久人人爽人人爽AV片 |
国产91色综合久久免费 |
亚洲伊人久久成综合人影院 |
久久精品国产精品青草 |
亚洲AV无码久久精品成人 |
国产精品成人99久久久久
|
久久综合亚洲色HEZYO国产 |
婷婷五月深深久久精品 |
久久久精品国产亚洲成人满18免费网站
|
久久久久97国产精华液好用吗 |
色综合久久无码中文字幕 |
欧美国产成人久久精品 |
日本三级久久网 |
99久久精品国产高清一区二区 |
97久久国产露脸精品国产
|
久久久久亚洲AV无码专区体验 |
久久久久一级精品亚洲国产成人综合AV区
|
国产精品狼人久久久久影院 |
久久国产热精品波多野结衣AV |
精品久久久无码21p发布 |
午夜福利91久久福利 |
久久狠狠一本精品综合网 |
人人狠狠综合久久亚洲婷婷 |
国产精品九九九久久九九 |
久久精品aⅴ无码中文字字幕重口 |
亚洲午夜无码AV毛片久久 |
一本久道久久综合狠狠躁AV |
日产久久强奸免费的看 |
亚洲国产精品无码久久九九 |
久久精品无码一区二区三区免费 |
国产午夜精品久久久久九九电影 |
国产午夜电影久久 |
色悠久久久久久久综合网 |
思思久久99热只有频精品66 |