锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久精品国产亚洲沈樵,午夜福利91久久福利,久久久中文字幕http://m.shnenglu.com/liyuxia713/category/10183.html韞掕窔鍓嶈鑰?/description>zh-cnSun, 06 Jun 2010 18:21:37 GMTSun, 06 Jun 2010 18:21:37 GMT60鍐呭瓨綆$悊http://m.shnenglu.com/liyuxia713/archive/2010/06/05/117211.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sat, 05 Jun 2010 01:34:00 GMThttp://m.shnenglu.com/liyuxia713/archive/2010/06/05/117211.htmlhttp://m.shnenglu.com/liyuxia713/comments/117211.htmlhttp://m.shnenglu.com/liyuxia713/archive/2010/06/05/117211.html#Feedback0http://m.shnenglu.com/liyuxia713/comments/commentRss/117211.htmlhttp://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>

 1char* test1()
 2{
 3    char str[] = "Hello World!";
 4    return str;
 5}

 6
 7char* test2()
 8{
 9    char *str = "Hello World!";
10    return str;
11}

12
13char* test3()
14{
15    static char str[] = "Hello World!";
16    return str;
17}

18
19void 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>



]]>
sscanfhttp://m.shnenglu.com/liyuxia713/archive/2010/04/25/113530.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 25 Apr 2010 12:13:00 GMThttp://m.shnenglu.com/liyuxia713/archive/2010/04/25/113530.htmlhttp://m.shnenglu.com/liyuxia713/comments/113530.htmlhttp://m.shnenglu.com/liyuxia713/archive/2010/04/25/113530.html#Feedback0http://m.shnenglu.com/liyuxia713/comments/commentRss/113530.htmlhttp://m.shnenglu.com/liyuxia713/services/trackbacks/113530.htmlint 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


]]>
sprintfhttp://m.shnenglu.com/liyuxia713/archive/2010/04/25/113525.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 25 Apr 2010 11:23:00 GMThttp://m.shnenglu.com/liyuxia713/archive/2010/04/25/113525.htmlhttp://m.shnenglu.com/liyuxia713/comments/113525.htmlhttp://m.shnenglu.com/liyuxia713/archive/2010/04/25/113525.html#Feedback0http://m.shnenglu.com/liyuxia713/comments/commentRss/113525.htmlhttp://m.shnenglu.com/liyuxia713/services/trackbacks/113525.htmlhttp://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><link>http://m.shnenglu.com/liyuxia713/archive/2010/04/19/112952.html</link><dc:creator>騫歌繍鑽?/dc:creator><author>騫歌繍鑽?/author><pubDate>Mon, 19 Apr 2010 00:49:00 GMT</pubDate><guid>http://m.shnenglu.com/liyuxia713/archive/2010/04/19/112952.html</guid><wfw:comment>http://m.shnenglu.com/liyuxia713/comments/112952.html</wfw:comment><comments>http://m.shnenglu.com/liyuxia713/archive/2010/04/19/112952.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/liyuxia713/comments/commentRss/112952.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/liyuxia713/services/trackbacks/112952.html</trackback:ping><description><![CDATA[<span style="FONT-FAMILY: 寰蔣闆呴粦">涓庡鍒舵瀯閫犲嚱鏁板拰澶嶅埗鎿嶄綔絎︿笉鍚岋紝緙栬瘧鍣ㄦ繪槸鎻愪緵鍚堟垚鏋愭瀯鍑芥暟銆?br><br>鍚堟垚鏋愭瀯鍑芥暟鍋氫粈涔堬紵<br>鎸夊璞″垱寤烘椂鐨勯嗗簭鎾ら攢姣忎釜闈瀞tatic鎴愬憳錛屽寘鎷寚閽堟垚鍛樸?br>鍙笉榪囦笉鍒犻櫎鎸囬拡鎴愬憳鎵鎸囧悜鐨勫璞°?/span> <img src ="http://m.shnenglu.com/liyuxia713/aggbug/112952.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/liyuxia713/" target="_blank">騫歌繍鑽?/a> 2010-04-19 08:49 <a href="http://m.shnenglu.com/liyuxia713/archive/2010/04/19/112952.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鎸囬拡瀛︿範3----浣曟椂闇瑕佽嚜琛屽畾涔夋瀽鏋勫嚱鏁?/title><link>http://m.shnenglu.com/liyuxia713/archive/2010/04/18/112928.html</link><dc:creator>騫歌繍鑽?/dc:creator><author>騫歌繍鑽?/author><pubDate>Sun, 18 Apr 2010 11:59:00 GMT</pubDate><guid>http://m.shnenglu.com/liyuxia713/archive/2010/04/18/112928.html</guid><wfw:comment>http://m.shnenglu.com/liyuxia713/comments/112928.html</wfw:comment><comments>http://m.shnenglu.com/liyuxia713/archive/2010/04/18/112928.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/liyuxia713/comments/commentRss/112928.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/liyuxia713/services/trackbacks/112928.html</trackback:ping><description><![CDATA[<span style="FONT-FAMILY: courier new">褰撳湪綾葷殑鏋勯犲嚱鏁頒綋涓敵璇蜂簡璧勬簮(濡傚唴瀛樼┖闂?錛岄渶瑕佸湪瀵硅薄琚攢姣佹椂榪涜閲婃斁鏃躲? <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://m.shnenglu.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> Test<br><img id=Codehighlighter1_11_148_Open_Image onclick="this.style.display='none'; Codehighlighter1_11_148_Open_Text.style.display='none'; Codehighlighter1_11_148_Closed_Image.style.display='inline'; Codehighlighter1_11_148_Closed_Text.style.display='inline';" src="http://m.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_11_148_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_11_148_Closed_Text.style.display='none'; Codehighlighter1_11_148_Open_Image.style.display='inline'; Codehighlighter1_11_148_Open_Text.style.display='inline';" src="http://m.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_11_148_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://m.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_11_148_Open_Text><span style="COLOR: #000000">{<br><img src="http://m.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br><img src="http://m.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    Test(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> ptr)<br><img id=Codehighlighter1_45_97_Open_Image onclick="this.style.display='none'; Codehighlighter1_45_97_Open_Text.style.display='none'; Codehighlighter1_45_97_Closed_Image.style.display='inline'; Codehighlighter1_45_97_Closed_Text.style.display='inline';" src="http://m.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_45_97_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_45_97_Closed_Text.style.display='none'; Codehighlighter1_45_97_Open_Image.style.display='inline'; Codehighlighter1_45_97_Open_Text.style.display='inline';" src="http://m.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>    </span><span id=Codehighlighter1_45_97_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://m.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_45_97_Open_Text><span style="COLOR: #000000">{<br><img src="http://m.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(ptr)<br><img id=Codehighlighter1_59_93_Open_Image onclick="this.style.display='none'; Codehighlighter1_59_93_Open_Text.style.display='none'; Codehighlighter1_59_93_Closed_Image.style.display='inline'; Codehighlighter1_59_93_Closed_Text.style.display='inline';" src="http://m.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_59_93_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_59_93_Closed_Text.style.display='none'; Codehighlighter1_59_93_Open_Image.style.display='inline'; Codehighlighter1_59_93_Open_Text.style.display='inline';" src="http://m.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>        </span><span id=Codehighlighter1_59_93_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://m.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_59_93_Open_Text><span style="COLOR: #000000">{<br><img src="http://m.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            p </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">[strlen(ptr)];<br><img src="http://m.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>        }</span></span><span style="COLOR: #000000">    <br><img src="http://m.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</span></span><span style="COLOR: #000000"><br><img src="http://m.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">Test()<br><img id=Codehighlighter1_109_126_Open_Image onclick="this.style.display='none'; Codehighlighter1_109_126_Open_Text.style.display='none'; Codehighlighter1_109_126_Closed_Image.style.display='inline'; Codehighlighter1_109_126_Closed_Text.style.display='inline';" src="http://m.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_109_126_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_109_126_Closed_Text.style.display='none'; Codehighlighter1_109_126_Open_Image.style.display='inline'; Codehighlighter1_109_126_Open_Text.style.display='inline';" src="http://m.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>    </span><span id=Codehighlighter1_109_126_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://m.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_109_126_Open_Text><span style="COLOR: #000000">{<br><img src="http://m.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        delete[] p;<br><img src="http://m.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</span></span><span style="COLOR: #000000"><br><img src="http://m.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">:<br><img src="http://m.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> p;<br><img src="http://m.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://m.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000">;</span></div> </span> <img src ="http://m.shnenglu.com/liyuxia713/aggbug/112928.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/liyuxia713/" target="_blank">騫歌繍鑽?/a> 2010-04-18 19:59 <a href="http://m.shnenglu.com/liyuxia713/archive/2010/04/18/112928.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鎸囬拡瀛︿範2--鍐呭瓨娉勯湶http://m.shnenglu.com/liyuxia713/archive/2010/04/18/112897.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 18 Apr 2010 04:06:00 GMThttp://m.shnenglu.com/liyuxia713/archive/2010/04/18/112897.htmlhttp://m.shnenglu.com/liyuxia713/comments/112897.htmlhttp://m.shnenglu.com/liyuxia713/archive/2010/04/18/112897.html#Feedback0http://m.shnenglu.com/liyuxia713/comments/commentRss/112897.htmlhttp://m.shnenglu.com/liyuxia713/services/trackbacks/112897.html錛?
 1#include <iostream>
 2using namespace std; 
 3
 4class 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
17int main()
18{
19    Stu *= new Stu(20); 
20    Stu *= new Stu(30);  
21    delete b;
22    return 0;
23    //or 鍏朵粬闅愯棌寮傚父
24
25    //瀵艱嚧鍐呭瓨娉勯湶
26    delete a;
27
28    return 0;
29}


]]>
鎸囬拡瀛︿範1--new &delete & destructorhttp://m.shnenglu.com/liyuxia713/archive/2010/04/18/112892.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 18 Apr 2010 02:58:00 GMThttp://m.shnenglu.com/liyuxia713/archive/2010/04/18/112892.htmlhttp://m.shnenglu.com/liyuxia713/comments/112892.htmlhttp://m.shnenglu.com/liyuxia713/archive/2010/04/18/112892.html#Feedback0http://m.shnenglu.com/liyuxia713/comments/commentRss/112892.htmlhttp://m.shnenglu.com/liyuxia713/services/trackbacks/112892.html1. 涓鑸寚閽堢殑new&delete

瀵逛簬鎸囬拡a,delete a涔嬪悗錛屾寚閽?/span>a 鐨勫湴鍧浠嶇劧鏄師鏉ョ殑鍦板潃(騫朵笉鏄疦ULL)錛屽彧涓嶈繃鎵鎸囧悜鐨勫璞¤閲婃斁浜嗭紝姝ゆ椂鎸囬拡瀛樻斁鐨勫間負闅忔満鐨勶紝鐢辯紪璇戝櫒紜畾銆?br>

 1     int *= new int(2);
 2     cout << "after new :" << endl;
 3     cout << "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 = " << *<< endl; 
//濂界殑緙栫▼涔犳儻
delete a;
= NULL;

甯歌鏂規硶鍒涘緩鐨勫璞★紝褰撳疄闄呭璞★紙鑰屼笉鏄璞$殑寮曠敤錛夎秴鍑轟綔鐢ㄥ煙鏃訛紝鎵嶄細榪愯鏋愭瀯鍑芥暟
鍔ㄦ佹柟娉曞垱寤虹殑瀵硅薄錛屽綋鍒犻櫎鎸囧悜鍔ㄦ佸垎閰嶅璞$殑鎸囬拡鏃訛紝鎵嶄細榪愯鏋愭瀯鍑芥暟銆?nbsp;        


2. 涓鑸被瀵硅薄鐨勫0鏄庝笌鍒濆鍖栵細涓嶇敤new涔熷彲浠ュ畾涔夌被瀵硅薄錛堝尯鍒簬java錛夛紝榛樿璋冩瀽鏋勫嚱鏁?br>娉細涓烘柟渚跨畝鍗曟紨紺猴紝騫舵病鏈夐伒寰笁娉曞垯
 1class 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
14void 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
27int main()
28{
29   func();   
30   return 0;
31}

榪欓噷鏈変竴涓渶瑕佹敞鎰忕殑鍦版柟錛屽氨鏄鏋渇unc閲岄潰鐨勪唬鐮佹槸鐩存帴鍐欏湪main閲岀殑鍒欎笉涓瀹氳皟鐢ㄦ瀽鏋勫嚱鏁?nbsp;錛岀敱緙栬瘧鍣ㄥ喅瀹氥?br>涓婇潰鏄痙ev c++, 涓嬮潰鏄痸c6.0鐨勮繍琛岀粨鏋?br>
 1
 2int 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>
 1class 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
14void 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
29int 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 GMThttp://m.shnenglu.com/liyuxia713/archive/2010/03/04/108897.htmlhttp://m.shnenglu.com/liyuxia713/comments/108897.htmlhttp://m.shnenglu.com/liyuxia713/archive/2010/03/04/108897.html#Feedback0http://m.shnenglu.com/liyuxia713/comments/commentRss/108897.htmlhttp://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 GMThttp://m.shnenglu.com/liyuxia713/archive/2010/01/21/106136.htmlhttp://m.shnenglu.com/liyuxia713/comments/106136.htmlhttp://m.shnenglu.com/liyuxia713/archive/2010/01/21/106136.html#Feedback0http://m.shnenglu.com/liyuxia713/comments/commentRss/106136.htmlhttp://m.shnenglu.com/liyuxia713/services/trackbacks/106136.htmlrand() 鍙幏寰椾吉闅忔満鏁般備絾鏄粎浠呰繖鏍峰啓鐨勮瘽錛屽悓涓孌典唬鐮佹瘡嬈¤繍琛岀▼搴忚幏寰楃殑闅忔満鏁扮浉鍚屻?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><link>http://m.shnenglu.com/liyuxia713/archive/2010/01/08/105170.html</link><dc:creator>騫歌繍鑽?/dc:creator><author>騫歌繍鑽?/author><pubDate>Fri, 08 Jan 2010 08:30:00 GMT</pubDate><guid>http://m.shnenglu.com/liyuxia713/archive/2010/01/08/105170.html</guid><wfw:comment>http://m.shnenglu.com/liyuxia713/comments/105170.html</wfw:comment><comments>http://m.shnenglu.com/liyuxia713/archive/2010/01/08/105170.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/liyuxia713/comments/commentRss/105170.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/liyuxia713/services/trackbacks/105170.html</trackback:ping><description><![CDATA[     鎽樿: <br>鈽?瀵逛簬鐖剁被鍑芥暟錛坴irtual銆侀潪virtual錛夛紝濡傛灉瀛愮被娌℃湁鍚屽悕鍑芥暟錛屽垯姝e父緇ф壙 <br> <br>鈽?瀵逛簬鐖剁被鍑芥暟錛坴irtual銆侀潪virtual錛夛紝濡傛灉瀛愮被鏈夊悓鍚嶅嚱鏁幫紝鏃犲悓鍨嬪嚱鏁幫紝鍒欎笉鑳借皟鐢ㄧ埗綾誨嚱鏁?<br> <br>鈽?瀵逛簬鐖剁被鍑芥暟錛坴irtual銆侀潪virtual錛夛紝濡傛灉鏈夊悓鍨嬪嚱鏁幫細 <br> <br>----闈瀡irtual鍑芥暟鐢辨寚閽堢被鍨嬪喅瀹氳皟鐢ㄥ摢涓?<br> <br>----virtual鍑芥暟鐢辨寚閽堟寚鍚戠殑瀵硅薄鍐沖畾璋冪敤鍝釜錛堣繍琛屾椂鍐沖畾錛?<br>  <a href='http://m.shnenglu.com/liyuxia713/archive/2010/01/08/105170.html'>闃呰鍏ㄦ枃</a><img src ="http://m.shnenglu.com/liyuxia713/aggbug/105170.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/liyuxia713/" target="_blank">騫歌繍鑽?/a> 2010-01-08 16:30 <a href="http://m.shnenglu.com/liyuxia713/archive/2010/01/08/105170.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>綾籹tatic鎴愬憳http://m.shnenglu.com/liyuxia713/archive/2010/01/08/105152.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Fri, 08 Jan 2010 04:22:00 GMThttp://m.shnenglu.com/liyuxia713/archive/2010/01/08/105152.htmlhttp://m.shnenglu.com/liyuxia713/comments/105152.htmlhttp://m.shnenglu.com/liyuxia713/archive/2010/01/08/105152.html#Feedback6http://m.shnenglu.com/liyuxia713/comments/commentRss/105152.htmlhttp://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
 4using namespace std; 
 5
 6class A
 7{
 8      //閲嶈澆杈撳嚭鎿嶄綔絎?nbsp;
 9      friend ostream& operator<<(ostream& outconst A&a)
10      {
11             out << a.m;
12             return out;
13      }

14      
15private:
16        int m ;
17 
18public:
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*<<endl;}    
30}
;
31
32int A::n = 10;
33A A::a(1);
34
35int 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錛宻trncpyhttp://m.shnenglu.com/liyuxia713/archive/2009/04/26/81155.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 26 Apr 2009 12:59:00 GMThttp://m.shnenglu.com/liyuxia713/archive/2009/04/26/81155.htmlhttp://m.shnenglu.com/liyuxia713/comments/81155.htmlhttp://m.shnenglu.com/liyuxia713/archive/2009/04/26/81155.html#Feedback1http://m.shnenglu.com/liyuxia713/comments/commentRss/81155.htmlhttp://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 GMThttp://m.shnenglu.com/liyuxia713/archive/2009/04/25/80918.htmlhttp://m.shnenglu.com/liyuxia713/comments/80918.htmlhttp://m.shnenglu.com/liyuxia713/archive/2009/04/25/80918.html#Feedback0http://m.shnenglu.com/liyuxia713/comments/commentRss/80918.htmlhttp://m.shnenglu.com/liyuxia713/services/trackbacks/80918.html1. 涓浜涘熀鏈被鍨嬬殑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 GMThttp://m.shnenglu.com/liyuxia713/archive/2009/03/25/79747.htmlhttp://m.shnenglu.com/liyuxia713/comments/79747.htmlhttp://m.shnenglu.com/liyuxia713/archive/2009/03/25/79747.html#Feedback0http://m.shnenglu.com/liyuxia713/comments/commentRss/79747.htmlhttp://m.shnenglu.com/liyuxia713/services/trackbacks/79747.htmlTechnorati 鏍囩:

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><link>http://m.shnenglu.com/liyuxia713/archive/2009/03/25/79748.html</link><dc:creator>騫歌繍鑽?/dc:creator><author>騫歌繍鑽?/author><pubDate>Wed, 25 Mar 2009 06:56:00 GMT</pubDate><guid>http://m.shnenglu.com/liyuxia713/archive/2009/03/25/79748.html</guid><wfw:comment>http://m.shnenglu.com/liyuxia713/comments/79748.html</wfw:comment><comments>http://m.shnenglu.com/liyuxia713/archive/2009/03/25/79748.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/liyuxia713/comments/commentRss/79748.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/liyuxia713/services/trackbacks/79748.html</trackback:ping><description><![CDATA[<p><strong>1. 妯℃澘瀹氫箟鍐呯殑鑷畾涔夌被鍨嬫垚鍛樿皟鐢ㄦ柟娉曪紙鐢╰ypename鏄劇ず璇存槑錛夛細</strong>綾誨彲浠ュ畾涔夌被鍨嬫垚鍛橈紝濡俿ize_type, size_t絳夌被鍨嬨傚湪瀹氫箟妯℃澘綾繪椂濡備綍璋冪敤瀹冨憿錛熶負浜嗚鏄庢槸綾誨瀷錛屾樉紺虹敤typename璇存槑銆? <p><font color=#ff00ff>template<class cl, class T></font> <p><font color=#ff00ff>cl func(cl* cl_p, T value)</font> <p><font color=#ff00ff>{</font> <p><font color=#ff00ff>       //<font color=#ff0000>cl::size_type * value;</font> </font><font color=#000000>// If cl::size_type is a type, then a declaration</font> <blockquote> <p><font color=#000000>                        // If cl::size_type is an object, then a multiplication</font> <p><font color=#ff00ff>typename cl::size_type *value;</font></p> </blockquote> <p><font color=#ff00ff>}                            </font> <p><strong>2. 闈炵被鍨嬫ā鏉垮艦鍙傜殑浣跨敤: </strong>妯℃澘闈炵被鍨嬪艦鍙傛槸妯℃澘瀹氫箟鍐呴儴鐨勫父閲忓?(鍦ㄩ渶瑕佸父閲忚〃杈懼紡鐨勬椂鍊?鍙互鐢ㄩ潪綾誨瀷褰㈠弬,濡傚畾涔夋暟緇勭殑闀垮害)銆? <p>鍥犱負闈炵被鍨嬫ā鏉垮艦鍙傞渶瑕佷紶閫掔殑鏄父閲忚〃杈懼紡錛屾墍浠ヤ笉鏀寔涓鑸殑闅愬紡綾誨瀷杞崲銆? <p><font color=#ff00ff>template<class T, size_t N> void fcn(T (&cl)[N]) {...}</font> <p><font color=#ff00ff>int x[20];</font> <p><font color=#ff00ff>fcn(x);</font> <p> <p><font color=#ff00ff></font><strong>3. 妯℃澘浣曟椂瀹炰緥鍖栵紵</strong>鍑芥暟澹版槑錛屽畾涔夊璞$殑寮曠敤鍜屾寚鍚戝璞$殑鎸囬拡閮戒笉浼氬疄渚嬪寲銆傚畾涔夌被瀵硅薄鎴栬皟鐢ㄥ嚱鏁版椂瀹炰緥鍖栥? <p><strong>4.friend妯℃澘澹版槑渚濊禆鎬э細</strong>錛?錛?褰撴巿浜堝緇欏畾妯℃澘鎵鏈夊疄渚嬬殑璁塊棶鏉冩椂錛屽湪浣滅敤鍩熶腑涓嶉渶瑕佸瓨鍦ㄨ綾繪ā鏉挎垨鍑芥暟妯℃澘鐨勫0鏄庛傜紪璇戝櫒灝嗗弸鍏冨0鏄庝篃褰撲綔綾繪垨鍑芥暟鐨勫0鏄庡寰咃紱錛?錛夋兂瑕侀檺鍒跺鐗瑰畾瀹炰緥鍖栫殑鍙嬪厓鍏崇郴鏃訛紝蹇呴』鍦ㄥ彲浠ョ敤浜庡弸鍏冨0鏄庝箣鍓嶅0鏄庣被鎴栧嚱鏁般? <p><strong>5.瀵逛簬涓嶅悓鍙傛暟鐨勫嚱鏁版ā鏉跨敤鐩稿悓鍙傛暟鍙互璋冪敤涔堬紵</strong>鍙互錛屼細璋冪敤闅愬紡杞崲銆? <p><font color=#ff00ff>#include<iostream> </font> <p><font color=#ff00ff>using namespace std; </font> <p><font color=#ff00ff>template<typename T1, typename T2> </font> <p><font color=#ff00ff>void print(const T1 &v1, const T2 &v2)</font><font color=#000000>  //鍙傛暟綾誨瀷涓嶅悓</font><font color=#ff00ff><br>{<br>    cout << "T1 = " << v1 <<endl;<br>    cout << "T2 = " << v2 <<endl;<br>} </font> <p><font color=#ff00ff>int main()<br>{<br>    print(1,2); </font><font color=#000000>//ok </font> <p><font color=#ff00ff>    int a=1;<br>    int b=2;<br>    print(a,b);</font><font color=#000000> //ok錛屽艦鍙傜被鍨嬬浉鍚?/font> <p><font color=#ff00ff>    return 0;<br>}</font><img height=1 alt="" src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=982263437555584821&page=RSS%ef%bc%9a%e6%a8%a1%e6%9d%bf%e4%b8%ad%e7%9a%84%e4%b8%80%e4%ba%9b%e8%a7%84%e5%88%99&referrer=" width=1 border=0><img style="POSITION: absolute" height=0px alt="" src="http://c.live.com/c.gif?NC=31263&NA=1149&PI=81873&RF=&DI=3919&PS=85545&TP=liyuxia-life.spaces.live.com&GT1=liyuxia-life" width=0px><br>鏂囩珷鏉ユ簮:<a >http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!266.entry</a> </p> <img src ="http://m.shnenglu.com/liyuxia713/aggbug/79748.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/liyuxia713/" target="_blank">騫歌繍鑽?/a> 2009-03-25 14:56 <a href="http://m.shnenglu.com/liyuxia713/archive/2009/03/25/79748.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>[瀵煎叆]妯℃澘緙栬瘧妯″瀷http://m.shnenglu.com/liyuxia713/archive/2009/03/24/79749.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Tue, 24 Mar 2009 07:50:00 GMThttp://m.shnenglu.com/liyuxia713/archive/2009/03/24/79749.htmlhttp://m.shnenglu.com/liyuxia713/comments/79749.htmlhttp://m.shnenglu.com/liyuxia713/archive/2009/03/24/79749.html#Feedback0http://m.shnenglu.com/liyuxia713/comments/commentRss/79749.htmlhttp://m.shnenglu.com/liyuxia713/services/trackbacks/79749.html1.鍖呭惈緙栬瘧妯″瀷錛坕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><link>http://m.shnenglu.com/liyuxia713/archive/2009/03/23/79750.html</link><dc:creator>騫歌繍鑽?/dc:creator><author>騫歌繍鑽?/author><pubDate>Mon, 23 Mar 2009 11:09:00 GMT</pubDate><guid>http://m.shnenglu.com/liyuxia713/archive/2009/03/23/79750.html</guid><wfw:comment>http://m.shnenglu.com/liyuxia713/comments/79750.html</wfw:comment><comments>http://m.shnenglu.com/liyuxia713/archive/2009/03/23/79750.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/liyuxia713/comments/commentRss/79750.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/liyuxia713/services/trackbacks/79750.html</trackback:ping><description><![CDATA[<p>鏋勯犲嚱鏁頒笉鑳藉畾涔変負virtual錛屾淳鐢熺被瀵硅薄鐨勫熀綾繪暟鎹垚鍛橀儴鍒嗗湪鍒濆鍖栧垪琛ㄤ腑鐢ㄥ熀綾繪瀯閫犲嚱鏁板垵濮嬪寲錛? <p>鍩虹被鏋愭瀯鍑芥暟搴斿畾涔変負virtual錛屽鍒舵搷浣滅涓鑸畾涔変負闈瀡irtual <p>鍦ㄥ熀綾繪瀯閫犲嚱鏁板拰鏋愭瀯鍑芥暟涓紝灝嗘淳鐢熺被瀵硅薄褰撲綔鍩虹被綾誨瀷瀵硅薄瀵瑰緟銆傦紙鍥犱負鍦ㄨ繖涓や釜鍑芥暟鐨勮繍琛岃繃紼嬩腑錛屽璞′笉鏄竴涓畬鏁寸殑媧劇敓綾葷被鍨嬶級 <p>綾葷殑澶嶅埗鎺у埗鐨勪笁娉曞垯鏈変釜渚嬪錛氬畾涔夛紙絀猴級铏氭瀯澶熷嚱鏁版椂鍙互涓嶅畾涔夋瀯閫犲嚱鏁板拰璧嬪煎嚱鏁般?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><img style="POSITION: absolute" height=0px alt="" src="http://c.live.com/c.gif?NC=31263&NA=1149&PI=81873&RF=&DI=3919&PS=85545&TP=liyuxia-life.spaces.live.com&GT1=liyuxia-life" width=0px><br>鏂囩珷鏉ユ簮:<a >http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!264.entry</a> </p> <img src ="http://m.shnenglu.com/liyuxia713/aggbug/79750.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/liyuxia713/" target="_blank">騫歌繍鑽?/a> 2009-03-23 19:09 <a href="http://m.shnenglu.com/liyuxia713/archive/2009/03/23/79750.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>[瀵煎叆]媧劇敓綾誨埌鍩虹被杞崲鐨勫彲璁塊棶鎬?/title><link>http://m.shnenglu.com/liyuxia713/archive/2009/03/22/79751.html</link><dc:creator>騫歌繍鑽?/dc:creator><author>騫歌繍鑽?/author><pubDate>Sun, 22 Mar 2009 12:22:00 GMT</pubDate><guid>http://m.shnenglu.com/liyuxia713/archive/2009/03/22/79751.html</guid><wfw:comment>http://m.shnenglu.com/liyuxia713/comments/79751.html</wfw:comment><comments>http://m.shnenglu.com/liyuxia713/archive/2009/03/22/79751.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/liyuxia713/comments/commentRss/79751.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/liyuxia713/services/trackbacks/79751.html</trackback:ping><description><![CDATA[<p>媧劇敓綾繪湰韜殑鎴愬憳鍜屽弸鍏冧換浣曠戶鎵挎椂閮藉彲浠ヤ嬌鐢ㄦ淳鐢熺被鍒板熀綾昏漿鎹€? <p>瀵逛簬鍚庝唬綾誨拰鐢ㄦ埛浠g爜錛? <p>public緇ф壙鏃訛細鍚庝唬綾誨拰鐢ㄦ埛浠g爜閮藉彲浠ャ? <p>protected緇ф壙鏃訛細鍚庝唬綾誨彲浠ワ紝鐢ㄦ埛浠g爜涓嶅彲浠ャ? <p>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><img style="POSITION: absolute" height=0px alt="" src="http://c.live.com/c.gif?NC=31263&NA=1149&PI=81873&RF=&DI=3919&PS=85545&TP=liyuxia-life.spaces.live.com&GT1=liyuxia-life" width=0px><br>鏂囩珷鏉ユ簮:<a >http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!263.entry</a> </p> <img src ="http://m.shnenglu.com/liyuxia713/aggbug/79751.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/liyuxia713/" target="_blank">騫歌繍鑽?/a> 2009-03-22 20:22 <a href="http://m.shnenglu.com/liyuxia713/archive/2009/03/22/79751.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>[瀵煎叆]媧劇敓綾誨鍩虹被鎴愬憳鐨勮闂潈闄?/title><link>http://m.shnenglu.com/liyuxia713/archive/2009/03/22/79752.html</link><dc:creator>騫歌繍鑽?/dc:creator><author>騫歌繍鑽?/author><pubDate>Sun, 22 Mar 2009 11:26:00 GMT</pubDate><guid>http://m.shnenglu.com/liyuxia713/archive/2009/03/22/79752.html</guid><wfw:comment>http://m.shnenglu.com/liyuxia713/comments/79752.html</wfw:comment><comments>http://m.shnenglu.com/liyuxia713/archive/2009/03/22/79752.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/liyuxia713/comments/commentRss/79752.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/liyuxia713/services/trackbacks/79752.html</trackback:ping><description><![CDATA[<p>1.媧劇敓綾誨鍩虹被private鎴愬憳娌℃湁璁塊棶鏉冮檺銆? <p>2.媧劇敓綾誨彧鑳介氳繃媧劇敓綾誨璞¤闂叾<font color=#ff0000>鍩虹被鐨刾rotected鎴愬憳</font>錛屾淳鐢熺被瀵瑰叾<font color=#ff0000>鍩虹被綾誨瀷瀵硅薄鐨刾rotected鎴愬憳</font>娌℃湁鐗規畩璁塊棶鏉冮檺銆? <p><font color=#ff00ff>#include<iostream><br>using namespace std; </font> <p><font color=#ff00ff>class Base<br>{<br>public:<br>    Base():i(0),j(0){};<br>protected:<br>    int i;<br>private:<br>    int j;<br>}; </font> <p><font color=#ff00ff>class Derived:public Base<br>{<br>    Derived():Base(){}; </font> <p><font color=#ff00ff>    print(const Base &b, const Derived &d)<br>    {<br>        int num = i;<br>        <font color=#ff0000>//num = b.i;</font> <font color=#404040><font color=#000000>//error. cannot access protected member declared in class 'Base'</font><br></font>        num = d.i;<br>        <font color=#ff0000>//num = d.j;</font> <font color=#000000>//error. cannot access private member declared in class 'Base'<br></font>    };<br>}; </font> <p><font color=#ff00ff>int main()<br>{<br>    return 0;<br>}</font><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%af%b9%e5%9f%ba%e7%b1%bb%e6%88%90%e5%91%98%e7%9a%84%e8%ae%bf%e9%97%ae%e6%9d%83%e9%99%90&referrer=" width=1 border=0><img style="POSITION: absolute" height=0px alt="" src="http://c.live.com/c.gif?NC=31263&NA=1149&PI=81873&RF=&DI=3919&PS=85545&TP=liyuxia-life.spaces.live.com&GT1=liyuxia-life" width=0px><br>鏂囩珷鏉ユ簮:<a >http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!262.entry</a> </p> <img src ="http://m.shnenglu.com/liyuxia713/aggbug/79752.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/liyuxia713/" target="_blank">騫歌繍鑽?/a> 2009-03-22 19:26 <a href="http://m.shnenglu.com/liyuxia713/archive/2009/03/22/79752.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>[瀵煎叆]鏋愭瀯鍑芥暟錛堝唴瀛樻硠婕忥紝涓夋硶鍒欙級http://m.shnenglu.com/liyuxia713/archive/2009/03/08/79754.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sun, 08 Mar 2009 13:25:00 GMThttp://m.shnenglu.com/liyuxia713/archive/2009/03/08/79754.htmlhttp://m.shnenglu.com/liyuxia713/comments/79754.htmlhttp://m.shnenglu.com/liyuxia713/archive/2009/03/08/79754.html#Feedback0http://m.shnenglu.com/liyuxia713/comments/commentRss/79754.htmlhttp://m.shnenglu.com/liyuxia713/services/trackbacks/79754.htmlTechnorati 鏍囩:

http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!255.entry



]]>
[瀵煎叆]錛堝鍒躲侀粯璁わ級鏋勯犲嚱鏁?/title><link>http://m.shnenglu.com/liyuxia713/archive/2009/03/08/79755.html</link><dc:creator>騫歌繍鑽?/dc:creator><author>騫歌繍鑽?/author><pubDate>Sun, 08 Mar 2009 13:00:00 GMT</pubDate><guid>http://m.shnenglu.com/liyuxia713/archive/2009/03/08/79755.html</guid><wfw:comment>http://m.shnenglu.com/liyuxia713/comments/79755.html</wfw:comment><comments>http://m.shnenglu.com/liyuxia713/archive/2009/03/08/79755.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/liyuxia713/comments/commentRss/79755.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/liyuxia713/services/trackbacks/79755.html</trackback:ping><description><![CDATA[<div style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px">Technorati 鏍囩: <a rel=tag>綾誨垵濮嬪寲鍒楄〃錛岄粯璁ゆ瀯閫犲嚱鏁幫紝澶嶅埗鏋勯犲嚱鏁?/a></div> <p><font color=#ff0000>鍒濆鍖栧垪琛細</font>閫氬父浣跨敤鍒濆鍖栨槸涓轟簡鎻愰珮鏁堢巼錛屽畠鐩存帴璋冪敤涓庡疄鍙傚尮閰嶇殑鏋勯犲嚱鏁般傘愬洜涓轟竴鑸湪鏋勯犲嚱鏁頒綋鍐呯殑澶嶅埗涔熺粡榪囧垵濮嬪寲-->璁$畻璧嬪?font color=#404040>錛堟鏃朵細璋冪敤澶嶅埗鏋勯犲嚱鏁幫級</font>涓や釜闃舵銆戯紱鐗瑰埆鐨勬湁浜涙椂鍊欏彧鑳界敤鍒濆鍖栧垪琛紝鍗充笉鑳借祴鍊肩殑鍙傛暟錛屽錛歝onst鎴栧紩鐢ㄧ被鍨嬬殑鎴愬憳錛屾病鏈夐粯璁ゆ瀯閫犲嚱鏁扮殑綾葷被鍨嬫垚鍛樸傚垵濮嬪寲鍒楄〃涓彉閲忕殑鍒濆鍖栭『搴忔槸鍏堝0鏄庣殑鍏堝垵濮嬪寲. <p><font color=#ff00ff>class cl1{ private: const int ci;  int &ri;};</font><font color=#404040> //ci,ri鍙兘鍦ㄥ垵濮嬪寲鍒楄〃涓繘琛屽垵濮嬪寲銆?/font> <p><font color=#404040><font color=#ff0000>榛樿鏋勯犲嚱鏁幫細</font></font><font color=#6600ff>鍏ㄩ儴褰㈠弬鏄粯璁ゅ疄鍙傜殑鏋勯犲嚱鏁頒篃鏄粯璁ゆ瀯閫犲嚱鏁般?/font> <p>鍙鑷繁瀹氫箟浜嗭紙浠繪剰鐨勶級鏋勯犲嚱鏁幫紝緙栬瘧鍣ㄥ氨涓嶄細涓烘垜浠悎鎴愰粯璁ゆ瀯閫犲嚱鏁般? <p><font color=#ff0000>澶嶅埗鏋勯犲嚱鏁幫細</font><font color=#6600ff>鍗曚釜褰㈠弬涓烘湰綾葷被鍨嬪璞$殑寮曠敤鐨勬瀯閫犲嚱鏁般傚浜庝笉鏀寔澶嶅埗鐨勭被鍨嬶紙濡侷O綾誨瀷錛変笉鑳界敤澶嶅埗鏋勯犲嚱鏁般傚鏋滆嚜宸卞畾涔変簡澶嶅埗鏋勯犲嚱鏁幫紙鑰屼笉鏄瀯閫犲嚱鏁幫紝鍗籌細鍙畾涔夋瀯閫犲嚱鏁幫紝浣嗘病鏈夊畾涔夊鍒舵瀯閫犲嚱鏁幫紝鍒欑紪璇戝櫒鍚堟垚澶嶅埗鏋勯犲嚱鏁幫級錛屽垯緙栬瘧鍣ㄤ笉浼氬悎鎴愬鍒舵瀯閫犲嚱鏁般傘愬鍒舵瀯閫犲嚱鏁伴渶瑕佺壒鍒敞鎰忔寚閽堟垚鍛橈紝浠ュ悗灝嗚鏄庛?/font> <p><font color=#ff00ff>ifstream file1("filename1");</font> <font color=#404040>//ok, direct initialization.</font> <p><font color=#ff00ff>ifstream file2="filename2";</font> <font color=#404040>//error</font> <p><font color=#ff0000>濡備綍闃叉澶嶅埗錛?/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><img style="POSITION: absolute" height=0px alt="" src="http://c.live.com/c.gif?NC=31263&NA=1149&PI=81873&RF=&DI=3919&PS=85545&TP=liyuxia-life.spaces.live.com&GT1=liyuxia-life" width=0px><br>鏂囩珷鏉ユ簮:<a >http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!254.entry</a> </p> <img src ="http://m.shnenglu.com/liyuxia713/aggbug/79755.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/liyuxia713/" target="_blank">騫歌繍鑽?/a> 2009-03-08 21:00 <a href="http://m.shnenglu.com/liyuxia713/archive/2009/03/08/79755.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>[瀵煎叆]綾葷殑涓浜涚壒孌婇檺鍒舵垚鍛?/title><link>http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79756.html</link><dc:creator>騫歌繍鑽?/dc:creator><author>騫歌繍鑽?/author><pubDate>Fri, 06 Mar 2009 13:57:00 GMT</pubDate><guid>http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79756.html</guid><wfw:comment>http://m.shnenglu.com/liyuxia713/comments/79756.html</wfw:comment><comments>http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79756.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/liyuxia713/comments/commentRss/79756.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/liyuxia713/services/trackbacks/79756.html</trackback:ping><description><![CDATA[<p><font color=#ff0000>inline鎴愬憳鍑芥暟錛?/font> 澹版槑鎴栧畾涔夋椂鎸囧畾涓篿nline閮藉彲浠ャ備綔鐢細鍦ㄨ皟鐢ㄥ鐩存帴鍦ㄨ鍐呭睍寮浠g爜錛屼互鎻愰珮鏁堢巼銆傜被鐨刬nline鎴愬憳鍑芥暟瀹氫箟鍦ㄥ寘鍚綾葷殑澶存枃浠朵腑銆?綾誨唴閮ㄥ畾涔夌殑鍑芥暟鍧囦負inline鍑芥暟銆? <p><font color=#ff0000>mutable鏁版嵁鎴愬憳</font>錛氫換浣曞嚱鏁幫紙鍖呮嫭綾籧onst鎴愬憳鍑芥暟錛夐兘鍙互淇敼mutable鏁版嵁鎴愬憳銆? <p><font color=#ff0000>explicit鏋勯犲嚱鏁幫細</font>澹版槑鏃舵寚瀹氾紝瀹氫箟鏃朵笉鍏佽閲嶅鎸囧畾涓篹xplicit銆備綔鐢細闃叉鍦ㄩ渶瑕侀殣寮忚漿鎹㈢殑涓婁笅鏂囦腑浣跨敤鏋勯犲嚱鏁般? <p><font color=#ff0000>friend鎴愬憳錛?/font>闈炵被鎴愬憳鍙互璁塊棶綾葷殑縐佹湁鎴愬憳銆傞渶瑕佺壒鍒敞鎰忓弸鍏冨0鏄庡拰浣滅敤鍩熴傚鏋滄兂灝嗭紙鍏朵粬綾葷殑錛夋垚鍛樺嚱鏁拌涓哄弸鍏冿紝蹇呴』鍏堝0鏄庯紱鑰屽鏋滄兂灝嗭紙鍏朵粬錛夌被鎴栭潪鎴愬憳鍑芥暟璁句負鍙嬪厓錛屽垯涓嶅繀棰勫厛澹版槑銆? <p><font color=#ff0000>static鏁版嵁鎴愬憳錛?/font>static鏁版嵁鎴愬憳涓嶇敤鏋勯犲嚱鏁幫紝鍦ㄧ被鐨勫閮ㄥ畾涔夛紝瀹氫箟鏃惰繘琛屽垵濮嬪寲銆? <p><font color=#ff0000>static鎴愬憳鍑芥暟錛?/font>澹版槑鏃舵寚瀹歴tatic綾誨瀷錛屽畾涔夋椂涓嶇敤閲嶅澹版槑銆傛病鏈塼his鎸囬拡銆? <p><font color=#ff0000>const static鏁版嵁鎴愬憳錛?/font>涓鑸湴綾葷殑static鏁版嵁鎴愬憳涓嶈兘鍦ㄧ被鐨勫唴閮ㄥ畾涔夈傛湁渚嬪灝辨槸鍙互鐢ㄥ父閲忚〃杈懼紡鍒濆鍖朿onst static鏁版嵁鎴愬憳錛屼笉榪囧嵆浣胯繖鏍蜂篃闇瑕佸湪綾誨畾涔変綋鐨勫閮ㄨ繘琛岃const static鏁版嵁鎴愬憳鐨勫畾涔夈? <p><font color=#404040>static鎴愬憳涓嶆槸綾誨璞$殑緇勬垚閮ㄥ垎錛岄潪static鏁版嵁鎴愬憳涓嶈兘鏄鎴愬憳鎵灞炵殑綾葷被鍨嬶紝鑰屽彧鑳芥槸瀵瑰簲鐨勬寚閽堝拰寮曠敤錛岃宻tatic鎴愬憳鍒欏彲浠ユ槸璇ユ垚鍛樻墍灞炵殑綾葷被鍨嬨?/font><img height=1 alt="" src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=982263437555584821&page=RSS%ef%bc%9a%e7%b1%bb%e7%9a%84%e4%b8%80%e4%ba%9b%e7%89%b9%e6%ae%8a%e9%99%90%e5%88%b6%e6%88%90%e5%91%98&referrer=" width=1 border=0><img style="POSITION: absolute" height=0px alt="" src="http://c.live.com/c.gif?NC=31263&NA=1149&PI=81873&RF=&DI=3919&PS=85545&TP=liyuxia-life.spaces.live.com&GT1=liyuxia-life" width=0px><br>鏂囩珷鏉ユ簮:<a >http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!252.entry</a> </p> <img src ="http://m.shnenglu.com/liyuxia713/aggbug/79756.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/liyuxia713/" target="_blank">騫歌繍鑽?/a> 2009-03-06 21:57 <a href="http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79756.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>[瀵煎叆]瀹瑰櫒閫傞厤鍣?/title><link>http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79757.html</link><dc:creator>騫歌繍鑽?/dc:creator><author>騫歌繍鑽?/author><pubDate>Fri, 06 Mar 2009 11:17:00 GMT</pubDate><guid>http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79757.html</guid><wfw:comment>http://m.shnenglu.com/liyuxia713/comments/79757.html</wfw:comment><comments>http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79757.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/liyuxia713/comments/commentRss/79757.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/liyuxia713/services/trackbacks/79757.html</trackback:ping><description><![CDATA[<blockquote> <p>queue             priority_queue         stack <p>闃熷垪                鍫?nbsp;                        鏍? <p>deque             vector                   deque <font color=#404040>//榛樿鐩稿叧鑱斿鍣ㄧ被鍨?/font> <p>push_front       闅忔満璁塊棶                 鏃?nbsp; <font color=#404040>//瀵瑰叧鑱斿鍣ㄧ殑瑕佹眰</font></p> </blockquote><img height=1 alt="" src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=982263437555584821&page=RSS%ef%bc%9a%e5%ae%b9%e5%99%a8%e9%80%82%e9%85%8d%e5%99%a8&referrer=" width=1 border=0><img style="POSITION: absolute" height=0px alt="" src="http://c.live.com/c.gif?NC=31263&NA=1149&PI=81873&RF=&DI=3919&PS=85545&TP=liyuxia-life.spaces.live.com&GT1=liyuxia-life" width=0px><br>鏂囩珷鏉ユ簮:<a >http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!251.entry</a> <img src ="http://m.shnenglu.com/liyuxia713/aggbug/79757.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/liyuxia713/" target="_blank">騫歌繍鑽?/a> 2009-03-06 19:17 <a href="http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79757.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>[瀵煎叆]榪唬鍣?/title><link>http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79758.html</link><dc:creator>騫歌繍鑽?/dc:creator><author>騫歌繍鑽?/author><pubDate>Fri, 06 Mar 2009 11:11:00 GMT</pubDate><guid>http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79758.html</guid><wfw:comment>http://m.shnenglu.com/liyuxia713/comments/79758.html</wfw:comment><comments>http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79758.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/liyuxia713/comments/commentRss/79758.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/liyuxia713/services/trackbacks/79758.html</trackback:ping><description><![CDATA[<p>鎰熻榪唬鍣ㄨ繖閮ㄥ垎鍑芥暟鐨勮繑鍥炵被鍨嬫槸娌″お寮勬槑鐧界殑錛屼互鍚庣敤鐨勬椂鍊欏緱澶氭敞鎰忕偣銆? <p><font color=#ff0000>1.鎻掑叆錛?/font>涓鑸彃鍏ユ槸鍦ㄧ粰瀹氱殑榪唬鍣ㄤ綅緗墠錛岃繖鏍鋒槸end榪唬鍣ㄤ篃璇炬甯哥紪璇戙傛彃鍏ョ殑鍏冪礌綾誨瀷蹇呴』涓巆鐨勭被鍨嬪畬鍏ㄤ竴鏍楓? <p>   <font color=#ff00ff>void c.push_back(t); </font> <p><font color=#ff00ff>    void c.insert(p,b,e); </font> <p><font color=#ff00ff>    void c.insert(p,n,t);</font> <p><font color=#ff00ff>    iter c.insert(p,t);</font> <p><font color=#ff0000>2.璧嬪?/font>錛?font color=#ff00ff>c1= c2</font> <p><font color=#ff00ff>     c.assign(b,e); c.assign(n,t)</font>  <font color=#404040>//鍏佽涓嶅悓鐨勫鍣紝涓嶅悓鐨勫厓绱狅紝鍙鍏冪礌綾誨瀷鍏煎銆?/font> <p><font color=#ff0000>3.璁塊棶錛?/font><font color=#ff00ff>c.back(); c.front(); </font> <blockquote> <p><font color=#ff00ff>c[n]; c.at[n];</font><font color=#404040> //榪欐牱鐨勪笅鏍囪闂鏄撹秺鐣屻傚悗鑰呰秺鐣屾槸鎶涘嚭 out_of_range寮傚父銆?/font></p> </blockquote> <p><font color=#ff0000>4.鍒犻櫎</font>錛?font color=#ff00ff>iter c.erase(p);</font> <blockquote> <p><font color=#ff00ff>iter c.erase(b,e);</font> <p><font color=#ff00ff>void c.clear();</font> <p><font color=#ff00ff>void c.pop_back();</font> <p><font color=#ff00ff>c.pop_front();</font></p> </blockquote><img height=1 alt="" src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=982263437555584821&page=RSS%ef%bc%9a%e8%bf%ad%e4%bb%a3%e5%99%a8&referrer=" width=1 border=0><img style="POSITION: absolute" height=0px alt="" src="http://c.live.com/c.gif?NC=31263&NA=1149&PI=81873&RF=&DI=3919&PS=85545&TP=liyuxia-life.spaces.live.com&GT1=liyuxia-life" width=0px><br>鏂囩珷鏉ユ簮:<a >http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!250.entry</a> <img src ="http://m.shnenglu.com/liyuxia713/aggbug/79758.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/liyuxia713/" target="_blank">騫歌繍鑽?/a> 2009-03-06 19:11 <a href="http://m.shnenglu.com/liyuxia713/archive/2009/03/06/79758.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>[瀵煎叆]const闄愬埗絎?/title><link>http://m.shnenglu.com/liyuxia713/archive/2009/02/28/79759.html</link><dc:creator>騫歌繍鑽?/dc:creator><author>騫歌繍鑽?/author><pubDate>Sat, 28 Feb 2009 13:38:00 GMT</pubDate><guid>http://m.shnenglu.com/liyuxia713/archive/2009/02/28/79759.html</guid><wfw:comment>http://m.shnenglu.com/liyuxia713/comments/79759.html</wfw:comment><comments>http://m.shnenglu.com/liyuxia713/archive/2009/02/28/79759.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/liyuxia713/comments/commentRss/79759.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/liyuxia713/services/trackbacks/79759.html</trackback:ping><description><![CDATA[<p>1. <font color=#ff0000>const鍙橀噺錛?/font><font color=#ff00ff>const type v;</font> 蹇呴』瀹氫箟鏃跺垵濮嬪寲錛屼笉鑳戒慨鏀瑰叾鍊箋?font color=#404040>澶囨敞錛氬叧浜巆onst鍙橀噺鐨勪綔鐢ㄥ煙瑕佺壒鍒敞鎰忥紝瀹冩槸灞閮ㄧ殑錛岃岄粯璁ょ殑C++鍙橀噺鏄叏灞鐨勩傞氳繃鍔爀xtern闄愬埗鍙互浠onst瀵硅薄鍙互鍦ㄥ叏灞琚闂傚浠g爜錛?欏轟究鎻愪竴涓媠tatic)</font> <p><font color=#404040>file1.cpp   </font><font color=#ff00ff>type v1; </font> <blockquote> <p><font color=#ff00ff>        const type v2;  </font><font color=#404040>//now,v2 is a local variable.</font> <p><font color=#ff00ff>        extern const type v3</font><font color=#404040>;//now,v3 is a global variable. must add 'extern'~. </font></p> </blockquote> <p><font color=#404040>file2.cpp   <font color=#ff00ff>type v1;</font> //  error.redeclaration.</font> <blockquote> <p><font color=#404040>        <font color=#ff00ff>extern type v1;</font> //ok.</font> <p><font color=#404040>        <font color=#ff00ff>type v2;</font> //ok.but not equivalent to v2 in file1.cpp</font> <p><font color=#404040>        <font color=#ff00ff>const type v3;</font>  // ok.but not equivalent to v3 in file1.cpp</font> <p><font color=#404040>        <font color=#ff00ff>extern const type v3;</font> //ok.equal to v3 in file1.cpp.  </font></p> </blockquote> <p>2. <font color=#ff0000>const寮曠敤錛?/font><font color=#ff00ff>const type& v;</font> 鏄寚鍚慶onst瀵硅薄鐨勫紩鐢ㄣ傞潪const寮曠敤鍙兘緇戝畾鍒頒笌璇ュ紩鐢ㄥ悓綾誨瀷鐨勫璞°傝宑onst寮曠敤鍒欏彲浠ョ粦瀹氬埌涓嶅悓浣嗙浉鍏崇殑綾誨瀷閭d釜鐨勫璞″拰鍙沖箋? <p>double dv = 1.0;  const int &iv = dv; 緙栬瘧鏃剁瓑浠蜂簬 <p>int temp = dv;  const int &iv = temp; //鍙互鐪嬪嚭瀵筰v鐨勪慨鏀瑰茍涓嶄細褰卞搷dv鐨勫? <p>3.<font color=#ff0000>const涓庢寚閽?/font>錛氾紙1錛?<font color=#ff0000>鎸囧悜const瀵硅薄鐨勬寚閽?</font> <font color=#ff00ff>const type* v;</font> 鏈夋椂璁頒綔<font color=#ff00ff>type const* v;</font>鍙互淇敼鎸囬拡錛屼絾涓嶈兘鐩存帴閫氳繃璇ユ寚閽堜慨鏀規寚閽堟寚鍚戠殑瀵硅薄銆傦紙鍙互閫氳繃瀹氫箟闈瀋onst鎸囬拡鎸囧悜璇ュ璞★紝浠庤屼慨鏀瑰叾鍊鹼級錛?錛?font color=#ff0000>const鎸囬拡:</font> type <font color=#ff00ff>*const v</font>;鍙互淇敼鎸囬拡鎸囧悜鐨勫璞★紝浣嗕笉鑳戒慨鏀規寚閽堟湰韜傦紙3錛?font color=#ff0000>鎸囧悜const瀵硅薄鐨刢onst鎸囬拡</font>錛?font color=#ff00ff>const type *const v;</font> 錛?font color=#404040>澶囨敞錛?font color=#ff00ff>typedef string * name;  const name v;</font> //</font><font color=#404040>v鐨勭被鍨嬫槸鎸囧悜string綾誨瀷鐨刢onst鎸囬拡銆傦級</font>  <p>4.<font color=#ff0000>const涓庝竴鑸嚱鏁幫細</font> (1)<font color=#ff00ff> const type1 func(type2 v);</font> 鍑芥暟榪斿洖鍊間負const; (2) <font color=#ff00ff>type1 func(const type2 v);</font>褰㈠弬涓篶onst鍙橀噺銆傚洜涓哄艦鍙備笉鏄紩鐢紝涓嶄慨鏀瑰疄鍙傜殑鍊鹼紝鎵浠ユ鏃剁殑const涓嶈搗鐗瑰埆鐨勪綔鐢紱錛?錛?font color=#ff00ff>type1 func(const type& v);</font> 褰㈠弬涓篶onst寮曠敤錛屼笉淇敼浼犻掑埌褰㈠弬鐨勫疄鍙傚箋?鎸囬拡鏃剁浉鍚岋紝涓嶄慨鏀規寚閽堟寚鍚戠殑瀵硅薄鐨勫箋? <p>5.<font color=#ff0000>const涓庣被鎴愬憳鍑芥暟錛堝父閲忔垚鍛樺嚱鏁幫級</font>錛歵ype func(type v) const;絳変環浜巘ype func(const *this,type v) const; 瀹冩槸鍊紅his鎸囬拡鏄寚鍚慶onst瀵硅薄鐨勬寚閽堬紝榪欎釜鍑芥暟涓嶆敼鍙樿皟鐢ㄨ鍑芥暟鐨勫璞?font color=#404040>銆傦紙澶囨敞錛氫簨瀹炰笂鏄笉鍙互鏄劇ず浣跨敤this鎸囬拡浣滀負褰㈠弬鐨勶紝浣嗗彲浠ュ湪鍑芥暟浣撲腑鏄劇ず鍦頒嬌鐢╰his鎸囬拡銆傦級</font> <p>6.<font color=#ff0000>const涓庤凱浠e櫒錛?/font><font color=#ff00ff>vector<type>::const_iterator it;  const vector<type>::iterator iter;</font> it鎸囧悜鐨勫厓绱犱笉鑳戒慨鏀癸紝iter鎸囧悜鐨勫厓绱犲彲浠ヤ慨鏀癸紝浣嗚凱浠e櫒鏈韓涓嶈兘淇敼銆? <p>7.<font color=#ff0000>const涓庡鍣細</font> <font color=#ff00ff>const vector<type> vec;</font> 闇瑕佹敞鎰忔鏃跺畾涔夌殑瀹瑰櫒榪唬鍣ㄥ繀欏繪槸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><img style="POSITION: absolute" height=0px alt="" src="http://c.live.com/c.gif?NC=31263&NA=1149&PI=81873&RF=&DI=3919&PS=85545&TP=liyuxia-life.spaces.live.com&GT1=liyuxia-life" width=0px><br>鏂囩珷鏉ユ簮:<a >http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!243.entry</a> </p> <img src ="http://m.shnenglu.com/liyuxia713/aggbug/79759.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/liyuxia713/" target="_blank">騫歌繍鑽?/a> 2009-02-28 21:38 <a href="http://m.shnenglu.com/liyuxia713/archive/2009/02/28/79759.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>[瀵煎叆]鍑芥暟鍙傛暟http://m.shnenglu.com/liyuxia713/archive/2009/02/28/79760.html騫歌繍鑽?/dc:creator>騫歌繍鑽?/author>Sat, 28 Feb 2009 11:18:00 GMThttp://m.shnenglu.com/liyuxia713/archive/2009/02/28/79760.htmlhttp://m.shnenglu.com/liyuxia713/comments/79760.htmlhttp://m.shnenglu.com/liyuxia713/archive/2009/02/28/79760.html#Feedback0http://m.shnenglu.com/liyuxia713/comments/commentRss/79760.htmlhttp://m.shnenglu.com/liyuxia713/services/trackbacks/79760.html1.闈炲紩鐢ㄥ艦鍙?/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 GMThttp://m.shnenglu.com/liyuxia713/archive/2009/02/27/79761.htmlhttp://m.shnenglu.com/liyuxia713/comments/79761.htmlhttp://m.shnenglu.com/liyuxia713/archive/2009/02/27/79761.html#Feedback0http://m.shnenglu.com/liyuxia713/comments/commentRss/79761.htmlhttp://m.shnenglu.com/liyuxia713/services/trackbacks/79761.htmlC椋庢牸瀛楃涓茬瓑浠蜂簬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><link>http://m.shnenglu.com/liyuxia713/archive/2009/02/27/79762.html</link><dc:creator>騫歌繍鑽?/dc:creator><author>騫歌繍鑽?/author><pubDate>Fri, 27 Feb 2009 13:09:00 GMT</pubDate><guid>http://m.shnenglu.com/liyuxia713/archive/2009/02/27/79762.html</guid><wfw:comment>http://m.shnenglu.com/liyuxia713/comments/79762.html</wfw:comment><comments>http://m.shnenglu.com/liyuxia713/archive/2009/02/27/79762.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/liyuxia713/comments/commentRss/79762.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/liyuxia713/services/trackbacks/79762.html</trackback:ping><description><![CDATA[<p><u><font color=#800080>鍔ㄦ佸垎閰嶇殑鏁扮粍錛?/font></u>鎴愬憳涓虹被綾誨瀷鏃剁敤榛樿鏋勯犲嚱鏁幫紝涓哄唴緗被鍨嬫椂涓嶈嚜鍔ㄥ垵濮嬪寲銆傦紙鍚屽嚱鏁板唴閮ㄥ彉閲忕殑鑷姩鍒濆鍖栵級 <p>鍙互閲囩敤 <font color=#ff00ff>new type[]()</font> 鐢卞唴緗被鍨嬬殑榛樿鍊煎垵濮嬪寲錛屾敞鎰忎笉鑳藉湪鍦嗘嫭鍙峰唴鍐欏叆鍊煎垵濮嬪寲銆? <p>浣嗘槸褰撴槸鍗曚釜瀵硅薄瀹氫箟鏃跺彲浠ワ細 <font color=#ff00ff>new type(value)</font> 鏄湁鏁堢殑<img height=1 alt="" src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=982263437555584821&page=RSS%ef%bc%9a%e5%8a%a8%e6%80%81%e5%86%85%e5%ad%98%e7%ae%a1%e7%90%86&referrer=" width=1 border=0><img style="POSITION: absolute" height=0px alt="" src="http://c.live.com/c.gif?NC=31263&NA=1149&PI=81873&RF=&DI=3919&PS=85545&TP=liyuxia-life.spaces.live.com&GT1=liyuxia-life" width=0px><br>鏂囩珷鏉ユ簮:<a >http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!231.entry</a> </p> <img src ="http://m.shnenglu.com/liyuxia713/aggbug/79762.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/liyuxia713/" target="_blank">騫歌繍鑽?/a> 2009-02-27 21:09 <a href="http://m.shnenglu.com/liyuxia713/archive/2009/02/27/79762.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://m.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.qinhaichang.cn" target="_blank">久久99毛片免费观看不卡</a>| <a href="http://www.desktx.cn" target="_blank">日韩精品久久久久久久电影</a>| <a href="http://www.aboto.cn" target="_blank">久久福利青草精品资源站</a>| <a href="http://www.dr-knoell-consult.com.cn " target="_blank">国产亚洲欧美成人久久片</a>| <a href="http://www.yunea.cn" target="_blank">久久久久久青草大香综合精品</a>| <a href="http://www.love2coffe.cn" target="_blank">久久亚洲sm情趣捆绑调教</a>| <a href="http://www.qancen.cn" target="_blank">99久久er这里只有精品18</a>| <a href="http://www.macsales.cn" target="_blank">久久人人爽人人爽AV片</a>| <a href="http://www.pophyh.cn" target="_blank">国产91色综合久久免费</a>| <a href="http://www.jisuxb.cn" target="_blank">亚洲伊人久久成综合人影院</a>| <a href="http://www.dfpt.net.cn" target="_blank">久久精品国产精品青草</a>| <a href="http://www.xyjsj88.com.cn" target="_blank">亚洲AV无码久久精品成人</a>| <a href="http://www.andz77.cn" target="_blank">国产精品成人99久久久久 </a>| <a href="http://www.hx0451.cn" target="_blank">久久综合亚洲色HEZYO国产</a>| <a href="http://www.lpxiu.cn" target="_blank">婷婷五月深深久久精品</a>| <a href="http://www.mingxiao123.cn" target="_blank">久久久精品国产亚洲成人满18免费网站 </a>| <a href="http://www.gjznet.cn" target="_blank">久久久久97国产精华液好用吗</a>| <a href="http://www.sun-q.cn" target="_blank">色综合久久无码中文字幕</a>| <a href="http://www.hunan168.cn" target="_blank">欧美国产成人久久精品</a>| <a href="http://www.focuan.cn" target="_blank">日本三级久久网</a>| <a href="http://www.2blood.cn" target="_blank">99久久精品国产高清一区二区</a>| <a href="http://www.wirja9.cn" target="_blank">97久久国产露脸精品国产 </a>| <a href="http://www.ahsxd.org.cn" target="_blank">久久久久亚洲AV无码专区体验</a>| <a href="http://www.mtsjnlaliji-syj.cn" target="_blank">久久久久一级精品亚洲国产成人综合AV区 </a>| <a href="http://www.designelite.com.cn" target="_blank">国产精品狼人久久久久影院</a>| <a href="http://www.mono2018.cn" target="_blank">久久国产热精品波多野结衣AV</a>| <a href="http://www.515176x.cn" target="_blank">精品久久久无码21p发布</a>| <a href="http://www.markey.com.cn" target="_blank">午夜福利91久久福利</a>| <a href="http://www.jyran.cn" target="_blank">久久狠狠一本精品综合网</a>| <a href="http://www.hwhack.cn" target="_blank">人人狠狠综合久久亚洲婷婷</a>| <a href="http://www.dguv.cn" target="_blank">国产精品九九九久久九九</a>| <a href="http://www.popotang.cn" target="_blank">久久精品aⅴ无码中文字字幕重口</a>| <a href="http://www.k7yg835v.cn" target="_blank">亚洲午夜无码AV毛片久久</a>| <a href="http://www.geigi.cn" target="_blank">一本久道久久综合狠狠躁AV</a>| <a href="http://www.hnyongsheng.cn" target="_blank">日产久久强奸免费的看</a>| <a href="http://www.1000su.cn" target="_blank">亚洲国产精品无码久久九九</a>| <a href="http://www.callmanager.cn" target="_blank">久久精品无码一区二区三区免费</a>| <a href="http://www.jcwmt.cn" target="_blank">国产午夜精品久久久久九九电影</a>| <a href="http://www.s9375.cn" target="_blank">国产午夜电影久久</a>| <a href="http://www.fj023.cn" target="_blank">色悠久久久久久久综合网</a>| <a href="http://www.djmb.net.cn" target="_blank">思思久久99热只有频精品66</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>