锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久99热精品,久久99久久99精品免视看动漫,久久国产精品-国产精品http://www.shnenglu.com/inwind/category/518.htmlzh-cnMon, 19 May 2008 17:13:52 GMTMon, 19 May 2008 17:13:52 GMT60WordFeatureLib緙栫▼絎旇http://www.shnenglu.com/inwind/articles/4247.htmlinwindinwindThu, 16 Mar 2006 10:45:00 GMThttp://www.shnenglu.com/inwind/articles/4247.htmlhttp://www.shnenglu.com/inwind/comments/4247.htmlhttp://www.shnenglu.com/inwind/articles/4247.html#Feedback0http://www.shnenglu.com/inwind/comments/commentRss/4247.htmlhttp://www.shnenglu.com/inwind/services/trackbacks/4247.html涓銆佸皬蹇?jī)鍐呭瓨鍒嗛厤锛屾槑纭瘡涓彉閲忕殑瀛樺偍浣嵕|?BR>浜屻佺畻娉曡璁★紝鍦ㄥ敖鍙兘澶栫殑寰幆鍐呮墽琛岃楁椂澶氱殑鎸囦護(hù)
涓夈佸皬蹇?jī)鎴愬憳鍙橀噺鐨勫紩鐢ㄤ紶閫掞紝闃叉瀵瑰唴瀛樼殑澶氭閲婃斁


鎬諱箣錛屾敞鎰忕畻娉曡璁★紝灝忓績(jī)鍐呭瓨鍒嗛厤銆傞渶瑕佸姞寮?/P>

inwind 2006-03-16 18:45 鍙戣〃璇勮
]]>
鏁扮粍鍜屾寚閽堢殑姣旇緝 http://www.shnenglu.com/inwind/articles/1958.htmlinwindinwindThu, 22 Dec 2005 05:42:00 GMThttp://www.shnenglu.com/inwind/articles/1958.htmlhttp://www.shnenglu.com/inwind/comments/1958.htmlhttp://www.shnenglu.com/inwind/articles/1958.html#Feedback0http://www.shnenglu.com/inwind/comments/commentRss/1958.htmlhttp://www.shnenglu.com/inwind/services/trackbacks/1958.html      鑰屾寚閽堝彉閲忓彧闇瑕佹寚瀹氱被鍨嬶紝緋葷粺鍙負(fù)璇ユ寚閽堝彉閲忓垎閰?瀛楄妭錛?2浣嶆満錛夊唴瀛橈紝鑰屼笉浼?xì)湄?fù)璇ュ彉閲忔墍鎸囧唴瀹瑰垎閰嶅唴瀛樸?BR>
2銆傛寚閽堝彉閲忔槸鏈夊瓨鍌ㄧ┖闂寸殑錛涜屾暟緇勫悕浠呬粎鏄竴涓爣鍙鳳紝娌℃湁瀹為檯瀛樺偍絀洪棿錛屽崟鍗曚竴涓暟緇勫悕灝卞彧鑳借〃紺鴻鏁扮粍鐨勭1涓厓绱犵殑鍦板潃銆俰nt a[10]; 瑙勫畾&a灝辯瓑浜?amp;a[0]鎴栬卆 .

3銆備緥濡?char str[]= "hello world"鍜宑har *p = "hello world"涓紝鏁扮粍str鏄厛鍒嗛厤緇欎粬鍏冪礌涓暟涓唴瀛橈紝鐒跺悗灝嗗悗闈㈢殑瀛楃涓插鍒剁粰榪欎釜絀洪棿錛堟敞鎰忥紝姝ゆ椂搴旇鑰冭檻\0瀛楃錛夛紱鑰宲鐨勫緩绔嬭繃紼嬫槸鍏堝湪闈?rùn)鎬佸瓨鍌ㄥ尯寤虹珛甯稿瓧絎︿覆"hello world\0"錛岀劧鍚庡皢p鎸囧悜榪欎釜甯稿瓧絎︿覆銆傛墍浠ユ暟緇剆tr涓厓绱犵殑鍐呭鍙互閫氳繃閲嶆柊璧嬪兼敼鍙橈紝鑰宲鎸囧悜鐨勫唴瀹逛笉鑳芥敼鍙樸?img src ="http://www.shnenglu.com/inwind/aggbug/1958.html" width = "1" height = "1" />

inwind 2005-12-22 13:42 鍙戣〃璇勮
]]>
C/C+璇█struct娣卞眰鎺㈢儲(chǔ) (杞嚜CSDN) http://www.shnenglu.com/inwind/articles/1753.htmlinwindinwindWed, 14 Dec 2005 10:27:00 GMThttp://www.shnenglu.com/inwind/articles/1753.htmlhttp://www.shnenglu.com/inwind/comments/1753.htmlhttp://www.shnenglu.com/inwind/articles/1753.html#Feedback0http://www.shnenglu.com/inwind/comments/commentRss/1753.htmlhttp://www.shnenglu.com/inwind/services/trackbacks/1753.html闃呰鍏ㄦ枃

inwind 2005-12-14 18:27 鍙戣〃璇勮
]]>
vc6鍑芥暟璋冪敤嫻呮瀽 http://www.shnenglu.com/inwind/articles/1752.htmlinwindinwindWed, 14 Dec 2005 10:26:00 GMThttp://www.shnenglu.com/inwind/articles/1752.htmlhttp://www.shnenglu.com/inwind/comments/1752.htmlhttp://www.shnenglu.com/inwind/articles/1752.html#Feedback0http://www.shnenglu.com/inwind/comments/commentRss/1752.htmlhttp://www.shnenglu.com/inwind/services/trackbacks/1752.html
鎴戝啓涓嬩簡(jiǎn)濡備笅浠g爜錛?BR>
int fun(int a,int b)
{
    
int i = 3;
    
return a+b+i;
}

int main()
{
    
int a = 1,b=2;
    
int result ;
    result 
= fun(1,2);
    
return result;
}

闈炲父綆鍗曘傚弽姹囩紪鍚?Debug鐗?鍙樻垚榪欐牱

1:    int fun(int a,int b)
2:    {
00401020   push        ebp
00401021   mov         ebp,esp
00401023   sub         esp,44h
00401026   push        ebx
00401027   push        esi
00401028   push        edi
00401029   lea         edi,[ebp-44h]
0040102C   mov         ecx,11h
00401031   mov         eax,0CCCCCCCCh
00401036   rep stos    dword ptr [edi]
3:        int i = 3;
00401038   mov         dword ptr [ebp-4],3
4:        return a+b+i;
0040103F   mov         eax,dword ptr [ebp
+8]
00401042   add         eax,dword ptr [ebp+0Ch]
00401045   add         eax,dword ptr [ebp-4]
5:    }
00401048   pop         edi
00401049   pop         esi
0040104A   pop         ebx
0040104B   mov         esp,ebp
0040104D   pop         ebp
0040104E   ret

7:    int main()
8:    {
00401060   push        ebp
00401061   mov         ebp,esp
00401063   sub         esp,4Ch
00401066   push        ebx
00401067   push        esi
00401068   push        edi
00401069   lea         edi,[ebp-4Ch]
0040106C   mov         ecx,13h
00401071   mov         eax,0CCCCCCCCh
00401076   rep stos    dword ptr [edi]
9:        int a = 1,b=2;
00401078   mov         dword ptr [ebp-4],1
0040107F   mov         dword ptr [ebp
-8],2
10:       int result ;
11:       result = fun(1,2);
00401086   push        2
00401088   push        1
0040108A   call        @ILT
+5(fun) (0040100a)
0040108F   add         esp,
8
00401092   mov         dword ptr [ebp-0Ch],eax
12:       return result;
00401095   mov         eax,dword ptr [ebp-0Ch]
13:   }
00401098   pop         edi
00401099   pop         esi
0040109A   pop         ebx
0040109B   add         esp,4Ch
0040109E   cmp         ebp,esp
004010A0   call        __chkesp (004010c0)
004010A5   mov         esp,ebp
004010A7   pop         ebp
004010A8   ret

鎴戜滑涓昏鏉ョ湅鐪嬪嚱鏁拌皟鐢ㄩ儴鍒?BR>
1.鍙傛暟鍘嬫爤
push 2
push 1
鍙傛暟浠庡彸鍚戝乏鍘嬫爤(__cdcel),esp閫掑噺

2.璋冪敤鍑芥暟
 call        @ILT+5(fun) (0040100a)
榪欐潯鎸囦護(hù)浼?xì)鎶婁笅涓琛屼唬鐮佺殑鍦板潃鍘嬫爤錛屼篃灝辨槸鍑芥暟榪斿洖鍦板潃銆傚悓鏃惰煩杞埌鍑芥暟鍏ュ彛澶?BR>
3.榪涘叆鍑芥暟浣?/STRONG>
push        ebp
mov         ebp,esp
棣栧厛淇濆瓨ebp鐨勫湴鍧錛岀劧鍚庢妸esp淇濆瓨鍒癳bp涓幓
00401023   sub         esp,44h
00401026   push        ebx
00401027   push        esi
00401028   push        edi
鍑忓皬stack鐨勬寚閽?娉ㄦ剰錛宻tack鏄粠鍐呭瓨鐨勯珮绔悜浣庣鐢熼暱鐨?錛屼負(fù)灞閮ㄥ彉閲忎繚鐣欎竴浜涚┖闂達(dá)紝榪欓噷鐨?4h涓嶆槸鍥哄畾鐨勶紝鐢辯紪璇戝櫒璁$畻寰楁潵
00401029   lea         edi,[ebp-44h]
0040102C   mov         ecx,11h
00401031   mov         eax,0CCCCCCCCh
00401036   rep stos    dword ptr [edi]
鐢?xCC濉厖灞閮ㄥ彉閲忕┖闂淬傝繖鏄疍ebug妯″紡鐗規(guī)湁鐨勶紝濡傛灉鏄瓧絎︿覆錛屼綘灝辯湅鍒拌鍒濆鍖栨垚"鐑儷鐑儷鐑儷"
鑷蟲錛屾暣涓爢鏍堝彉鎴?BR>|-----------------|
|    灞閮ㄥ彉閲?   |
|-----------------|
|    灞閮ㄥ彉閲?    |<----ebp-4
|-----------------|
|    old ebp          |<----ebp
|-----------------|
| 鍑芥暟榪斿洖鍦板潃| <----ebp+4
|-----------------|
|      鍙傛暟1         | <----ebp+8
|-----------------|
|      鍙傛暟2         |
|-----------------|

Next:
int i = 3;
00401038   mov         dword ptr [ebp-4],3
榪欓噷浣犵湅鍒癧ebp-4]灝辨槸絎竴涓眬閮ㄥ彉閲廼浜?BR>0040103F   mov         eax,dword ptr [ebp+8]
00401042   add         eax,dword ptr [ebp+0Ch]
00401045   add         eax,dword ptr [ebp-4]
[ebp+8],[ebp+0Ch]鍒嗗埆鏄痑鍜宐浜?BR>
4.鍑芥暟榪斿洖
鍑芥暟鐨勭粨鏋滈兘鏄斁鍦╡ax涓?ps:浣犲彲浠ュ湪vc鐨剋atch紿楀彛杈撳叆@EAX錛屽氨鍙互鐩存帴鐪嬪埌鍑芥暟榪斿洖鍊間簡(jiǎn)錛?BR>00401048   pop         edi
00401049   pop         esi
0040104A   pop         ebx
0040104B   mov         esp,ebp
0040104D   pop         ebp
0040104E   ret
鎶奺di,esi,ebx鎭㈠錛岀劧鍚庢仮澶峞sp,ebp,榪欐椂鍑芥暟鐨勮繑鍥炲湴鍧灝卞湪鏍堥《錛岃皟鐢╮et灝卞彲浠ヨ繑鍥炰簡(jiǎn)銆?BR>

閭e鏋滄敼鍙樺嚱鏁扮殑榪斿洖鍦板潃浼?xì)鎬庢牱錛?BR>ok,鎴戜滑淇敼涓涓嬩唬鐮侊細(xì)
#include <stdio.h>
void fun2()
{
    printf(
"fun2() called");
}

int fun(int a,int b)
{
    
int i = 3;
    printf(
"return address:0x%x\n",&i+2);
    printf(
"fun2 address:0x%x\n",&fun2);
    
/*int *p = (int*)&fun2;
    __asm
    {
        mov ebx,p
        mov dword ptr[ebp+4],ebx
    }
*/
    
*(&i+2)=(int)&fun2; //modify return address
    return a+b+i;
}

int main()
{
    
int a = 1,b=2;
    
int result ;
    result 
= fun(1,2);
    
return result;
}

Wow,榪欐椂錛屾垜浠氨浼?xì)鍙戠幇fun2琚皟鐢ㄤ簡(jiǎn)銆傝繖灝辨槸Buffer overrun(緙撳啿婧㈠嚭)鎵鍋氱殑浜嬫儏鍚с?BR>

5.鏈鍚庝竴姝ワ紝璋冪敤鑰呰皟鏁村爢鏍堟寚閽?/STRONG>
call        @ILT+5(fun) (0040100a)
 add         esp,8
涓轟粈涔堣璋冩暣鍛紝鍥犱負(fù)璋冪敤涔嬪墠push涓や釜鍙傛暟榪涘叆鏍堬紝鐜板湪瑕佹仮澶嶅畠
 mov         dword ptr [ebp-0Ch],eax
榪欏彞璇濆氨鏄韓鐢ㄥ嚱鏁拌皟鐢ㄧ殑鏋滃疄浜?EAX淇濆瓨浜?jiǎn)鍑芥暟鐨剺q斿洖鍊?



inwind 2005-12-14 18:26 鍙戣〃璇勮
]]>
鍑芥暟瀵硅薄http://www.shnenglu.com/inwind/articles/1751.htmlinwindinwindWed, 14 Dec 2005 10:24:00 GMThttp://www.shnenglu.com/inwind/articles/1751.htmlhttp://www.shnenglu.com/inwind/comments/1751.htmlhttp://www.shnenglu.com/inwind/articles/1751.html#Feedback0http://www.shnenglu.com/inwind/comments/commentRss/1751.htmlhttp://www.shnenglu.com/inwind/services/trackbacks/1751.html鍑芥暟鎸囬拡鐨勪竴縐嶆浛浠g瓥鐣ユ槸Function object錛堝嚱鏁板璞★級(jí)銆?/P>

鍑芥暟瀵硅薄涓庡嚱鏁版寚閽堢浉姣旇緝鏈変袱涓柟闈㈢殑浼樼偣錛氶鍏堝鏋滆閲嶈澆鐨勮皟鐢ㄦ搷浣滅鏄痠nline鍑芥暟鍒欑紪璇戝櫒鑳藉鎵ц鍐呰仈緙栬瘧錛屾彁渚涘彲鑳界殑鎬ц兘濂藉錛涘叾嬈″嚱鏁板璞″彲浠ユ嫢鏈変換鎰忔暟鐩殑棰濆鏁版嵁錛岀敤榪欎簺鏁版嵁鍙互緙撳啿緇撴灉錛屼篃鍙互緙撳啿鏈夊姪浜庡綋鍓嶆搷浣滅殑鏁版嵁銆?/P>

鍑芥暟瀵硅薄鏄竴涓被錛屽畠閲嶈澆浜?jiǎn)鍑芥暟璋冪敤鎿嶄綔绗perator() ,璇ユ搷浣滅灝佽浜?jiǎn)涓涓嚱鏁扮殑鍔熻兘銆傚吀鍨嬫儏鍐典笅鍑芥暟瀵硅薄琚綔涓哄疄鍙備紶閫掔粰娉涘瀷綆楁硶錛屽綋鐒舵垜浠篃鍙互瀹氫箟鐙珛鐨勫嚱鏁板璞″疄渚嬨?/P>

鏉ョ湅涓嬮潰鐨勪簩涓緥瀛愶細(xì) 姣旇緝鐞嗚В浼?xì)鏇村ソ浜涘Q?/P>

#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
class Sum {
int val;
public:
Sum(int i) :val(i) { }

//褰撳湪闇瑕乮nt鐨勫湴鏂癸紝Sum灝嗚嚜鍔ㄨ漿鎹負(fù)int綾誨瀷
//榪欓噷鏄負(fù)浜?jiǎn)鏂逛究cout<<Sum鐨勫疄渚嬶紱
operator int() const { return val; }

//鍐欏湪綾諱腑鐨勫嚱鏁頒唬鐮佷竴鑸粯璁や負(fù)鍐呰仈浠g爜
int operator()(int i) { return val+=i; }
};

void f(vector<int> v)
{
Sum s = 0; //Sum s = 0絳変環(huán)浜嶴um s(0),涓嶇瓑浠蜂簬Sum s;s = 0;

//瀵箆ector<int>涓殑鍏冪礌姹傚拰
//鍑芥暟瀵硅薄琚綔涓哄疄鍙備紶閫掔粰娉涘瀷綆楁硶
s = for_each(v.begin(), v.end(), s);

cout << "the sum is " << s << "\n";

//鏇寸畝鍗曠殑鍐欐硶錛屽畾涔夌嫭绔嬬殑鍑芥暟瀵硅薄瀹炰緥
cout << "the sum is " << for_each(v.begin(), v.end(), Sum(0)) << "\n";
}


int main()
{
vector<int> v;
v.push_back(3); v.push_back(2); v.push_back(1);
f(v);
system("pause");
return 0;
}
錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛?BR>#include <iostream>
#include <list>
#include <algorithm>
#include "print.hpp"
using namespace std;

// function object that adds the value with which it is initialized
class AddValue {
  private:
    int theValue;    // the value to add
  public:
    // constructor initializes the value to add
    AddValue(int v) : theValue(v) {
    }

    // the ``function call'' for the element adds the value
    void operator() (int& elem) const {
        elem += theValue;
    }
};

int main()
{
    list<int> coll;

    // insert elements from 1 to 9
    for (int i=1; i<=9; ++i) {
        coll.push_back(i);
    }

    PRINT_ELEMENTS(coll,"initialized:                ");

    // add value 10 to each element
    for_each (coll.begin(), coll.end(),    // range
              AddValue(10));               // operation

    PRINT_ELEMENTS(coll,"after adding 10:            ");

    // add value of first element to each element
    for_each (coll.begin(), coll.end(),    // range
              AddValue(*coll.begin()));    // operation

    PRINT_ELEMENTS(coll,"after adding first element: ");
}
-------------------------------------------------------------------------
operator()涓殑鍙傛暟涓篶ontainer涓殑鍏冪礌
錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛?BR>
鍙﹀鐨勫疄渚嬶細(xì)
Function Objects as Sorting Criteria

Programmers often need a sorted collection of elements that have a special class (for example, a collection of persons). However, you either don't want to use or you can't use the usual operator < to sort the objects. Instead, you sort the objects according to a special sorting criterion based on some member function. In this regard, a function object can help. Consider the following example:

   // fo/sortl.cpp

   #include <iostream>
   #include <string>
   #include <set>
   #include <algorithm>
   using namespace std;


   class Person {
     public:
       string firstname() const;
       string lastname() const;
       ...
   };


   /* class for function predicate
    * - operator() returns whether a person is less than another person
    */
   class PersonSortCriterion {
     public:
       bool operator() (const Person& p1, const Person& p2) const {
           /* a person is less than another person
            * - if the last name is less
            * - if the last name is equal and the first name is less
            */
           return p1.lastname()<p2.1astname() ||
                  (! (p2.1astname()<p1.lastname()) &&
                   p1.firstname()<p2.firstname());
       }
   };


   int main()
   {

       //declare set type with special sorting criterion
       typedef set<Person,PersonSortCriterion> PersonSet;

       //create such a collection
       PersonSet coll;
       ...


       //do something with the elements
       PersonSet::iterator pos;
       for (pos = coll.begin(); pos != coll.end();++pos) {
           ...
       }
       ...
   }


//fo/foreach3.cpp #include <iostream> #include <vector> #include <algorithm> using namespace std; //function object to process the mean value class MeanValue { private: long num; //number of elements long sum; //sum of all element values public: //constructor MeanValue() : num(0), sum(0) { } //"function call" //-process one more element of the sequence void operator() (int elem) { num++; //increment count sum += elem; //add value } //return mean value double value() { return static_cast<double>(sum) / static_cast<double>(num); } }; int main() { vector<int> coll; //insert elments from 1 to 8 for (int i=1; i<=8; ++i) { coll.push_back(i); } //process and print mean value MeanValue mv = for_each (coll.begin(), coll.end(), //range MeanValue()); //operation cout << "mean value: " << mv.value() << endl; }


inwind 2005-12-14 18:24 鍙戣〃璇勮
]]>
C++鐨?縐嶇被鍨嬭漿鎹?/title><link>http://www.shnenglu.com/inwind/articles/1585.html</link><dc:creator>inwind</dc:creator><author>inwind</author><pubDate>Wed, 07 Dec 2005 02:50:00 GMT</pubDate><guid>http://www.shnenglu.com/inwind/articles/1585.html</guid><wfw:comment>http://www.shnenglu.com/inwind/comments/1585.html</wfw:comment><comments>http://www.shnenglu.com/inwind/articles/1585.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/inwind/comments/commentRss/1585.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/inwind/services/trackbacks/1585.html</trackback:ping><description><![CDATA[<DIV><STRONG>   涓銆丆 椋庢牸錛圕-style錛夊己鍒惰漿鍨嬪涓嬶細(xì)</STRONG> </DIV> <P>    (T) expression // cast expression to be of type T <BR>    鍑芥暟椋庢牸錛團(tuán)unction-style錛夊己鍒惰漿鍨嬩嬌鐢ㄨ繖鏍風(fēng)殑璇硶錛?BR>    T(expression) // cast expression to be of type T <BR>    榪欎袱縐嶅艦寮忎箣闂存病鏈夋湰璐ㄤ笂鐨勪笉鍚岋紝瀹冪函綺瑰氨鏄竴涓妸鎷彿鏀懼湪鍝殑闂銆傛垜鎶婅繖涓ょ褰㈠紡縐頒負(fù)鏃ч鏍鹼紙old-style錛夌殑寮哄埗杞瀷銆?</P> <P><STRONG>   浜屻?C++鐨勫洓縐嶅己鍒惰漿鍨嬪艦寮忥細(xì)</STRONG></P> <P>銆銆C++ 鍚屾椂鎻愪緵浜?jiǎn)鍥浛U嶆柊鐨勫己鍒惰漿鍨嬪艦寮忥紙閫氬父縐頒負(fù)鏂伴鏍肩殑鎴?C++ 椋庢牸鐨勫己鍒惰漿鍨嬶級(jí)錛?<BR>銆銆const_cast(expression) <BR>銆銆dynamic_cast(expression) <BR>銆銆reinterpret_cast(expression) <BR>銆銆static_cast(expression) </P> <P>銆銆姣忎竴縐嶉傜敤浜庣壒瀹氱殑鐩殑錛?</P> <P>銆銆dynamic_cast 涓昏鐢ㄤ簬鎵ц鈥滃畨鍏ㄧ殑鍚戜笅杞瀷錛坰afe downcasting錛夆濓紝涔熷氨鏄錛岃紜畾涓涓璞℃槸鍚︽槸涓涓戶鎵夸綋緋諱腑鐨勪竴涓壒瀹氱被鍨嬨傚畠鏄敮涓涓嶈兘鐢ㄦ棫椋庢牸璇硶鎵ц鐨勫己鍒惰漿鍨嬶紝涔熸槸鍞竴鍙兘鏈夐噸澶ц繍琛屾椂浠d環(huán)鐨勫己鍒惰漿鍨嬨?BR>    <BR>     static_cast 鍙互琚敤浜庡己鍒墮殣鍨嬭漿鎹紙渚嬪錛宯on-const 瀵硅薄杞瀷涓?const 瀵硅薄錛宨nt 杞瀷涓?double錛岀瓑絳夛級(jí)錛屽畠榪樺彲浠ョ敤浜庡緢澶氳繖鏍風(fēng)殑杞崲鐨勫弽鍚戣漿鎹紙渚嬪錛寁oid* 鎸囬拡杞瀷涓烘湁綾誨瀷鎸囬拡錛屽熀綾繪寚閽堣漿鍨嬩負(fù)媧劇敓綾繪寚閽堬級(jí)錛屼絾鏄畠涓嶈兘灝嗕竴涓?const 瀵硅薄杞瀷涓?non-const 瀵硅薄錛堝彧鏈?const_cast 鑳藉仛鍒幫級(jí)錛屽畠鏈鎺ヨ繎浜嶤-style鐨勮漿鎹€?BR>    <BR>銆銆 const_cast 涓鑸敤浜庡己鍒舵秷闄ゅ璞$殑甯擱噺鎬с傚畠鏄敮涓鑳藉仛鍒拌繖涓鐐圭殑 C++ 椋庢牸鐨勫己鍒惰漿鍨嬨?</P> <P>銆銆 reinterpret_cast 鏄壒鎰忕敤浜庡簳灞傜殑寮哄埗杞瀷錛屽鑷村疄鐜頒緷璧栵紙implementation-dependent錛夛紙灝辨槸璇達(dá)紝涓嶅彲縐繪錛夌殑緇撴灉錛屼緥濡傦紝灝嗕竴涓寚閽堣漿鍨嬩負(fù)涓涓暣鏁般傝繖鏍風(fēng)殑寮哄埗杞瀷鍦ㄥ簳灞備唬鐮佷互澶栧簲璇ユ瀬涓虹綍瑙併?BR>銆銆<BR>銆銆鏃ч鏍肩殑寮哄埗杞瀷渚濈劧鍚堟硶錛屼絾鏄柊鐨勫艦寮忔洿鍙彇銆傞鍏堬紝鍦ㄤ唬鐮佷腑瀹冧滑鏇村鏄撹瘑鍒紙鏃犺鏄漢榪樻槸鍍?grep 榪欐牱鐨勫伐鍏烽兘鏄姝わ級(jí)錛岃繖鏍峰氨綆鍖栦簡(jiǎn)鍦ㄤ唬鐮佷腑瀵繪壘綾誨瀷緋葷粺琚牬鍧忕殑鍦版柟鐨勮繃紼嬨傜浜岋紝鏇寸簿紜湴鎸囧畾姣忎竴涓己鍒惰漿鍨嬬殑鐩殑錛屼嬌寰楃紪璇戝櫒璇婃柇浣跨敤閿欒鎴愪負(fù)鍙兘銆備緥濡傦紝濡傛灉浣犺瘯鍥句嬌鐢ㄤ竴涓?const_cast 浠ュ鐨勬柊椋庢牸寮哄埗杞瀷鏉ユ秷闄ゅ父閲忔э紝浣犵殑浠g爜灝嗘棤娉曠紪璇戙?</P> <P>==  <BR><STRONG>==  dynamic_cast .vs. static_cast</STRONG> <BR>==</P> <DIV> <P>class B { ... };<BR>class D : public B { ... };</P> <P>void f(B* pb)<BR>{<BR>   D* pd1 = dynamic_cast<D*>(pb);<BR>   D* pd2 = static_cast<D*>(pb);<BR>}</P> <P>If pb really points to an object of type D, then pd1 and pd2 will get the same value. They will also get the same value if pb == 0. </P> <P>If pb points to an object of type B and not to the complete D class, then dynamic_cast will know enough to return zero. However, static_cast relies on the programmer鈥檚 assertion that pb points to an object of type D and simply returns a pointer to that supposed D object.</P></DIV> <P>    鍗砫ynamic_cast鍙敤浜庣戶鎵夸綋緋諱腑鐨勫悜涓嬭漿鍨嬶紝鍗沖皢鍩虹被鎸囬拡杞崲涓烘淳鐢熺被鎸囬拡錛屾瘮static_cast鏇翠弗鏍兼洿瀹夊叏銆俤ynamic_cast鍦ㄦ墽琛屾晥鐜囦笂姣攕tatic_cast瑕佸樊涓浜?浣唖tatic_cast鍦ㄦ洿瀹戒笂鑼冨洿鍐呭彲浠ュ畬鎴愭槧灝?榪欑涓嶅姞闄愬埗鐨勬槧灝勪即闅忕潃涓嶅畨鍏ㄦ?static_cast瑕嗙洊鐨勫彉鎹㈢被鍨嬮櫎綾誨眰嬈$殑闈?rùn)鎬佸鑸互澶?榪樺寘鎷棤鏄犲皠鍙樻崲,紿勫寲鍙樻崲(榪欑鍙樻崲浼?xì)瀵艰嚧瀵硅薄鍒囩?涓㈠け淇℃伅),鐢╒OID*鐨勫己鍒跺彉鎹?闅愬紡綾誨瀷鍙樻崲絳?..</P> <P><BR>==<BR><STRONG>==  static_cast .vs. reinterpret_cast</STRONG> <BR>==</P> <P>    reinterpret_cast鏄負(fù)浜?jiǎn)鏄牉畡鍒颁竴涓畬鍏ㄤ笉鍚岀被鍨嬬殑鎰忔?榪欎釜鍏抽敭璇嶅湪鎴戜滑闇瑕佹妸綾誨瀷鏄犲皠鍥炲師鏈夌被鍨嬫椂鐢ㄥ埌瀹?鎴戜滑鏄犲皠鍒扮殑綾誨瀷浠呬粎鏄負(fù)浜?jiǎn)鏁呭紕鐜勮櫄鍜屽叾浠栫洰鐨?榪欐槸鎵鏈夋槧灝勪腑鏈鍗遍櫓鐨?(榪欏彞璇濇槸C++緙栫▼鎬濇兂涓殑鍘熻瘽)</P> <P>    static_cast 鍜?reinterpret_cast 鎿嶄綔絎︿慨鏀逛簡(jiǎn)鎿嶄綔鏁扮被鍨? 瀹冧滑涓嶆槸浜掗嗙殑; static_cast 鍦ㄧ紪璇戞椂浣跨敤綾誨瀷淇℃伅鎵ц杞崲, 鍦ㄨ漿鎹㈡墽琛屽繀瑕佺殑媯(gè)嫻?璇稿鎸囬拡瓚婄晫璁$畻, 綾誨瀷媯(gè)鏌?. 鍏舵搷浣滄暟鐩稿鏄畨鍏ㄧ殑. 鍙︿竴鏂歸潰, reinterpret_cast 浠呬粎鏄噸鏂拌В閲婁簡(jiǎn)緇欏嚭鐨勫璞$殑姣旂壒妯″瀷鑰屾病鏈夎繘琛屼簩榪涘埗杞崲, 渚嬪瓙濡備笅:</P> <P>    int n=9; double d=static_cast < double > (n); </P> <P>    涓婇潰鐨勪緥瀛愪腑, 鎴戜滑灝嗕竴涓彉閲忎粠 int 杞崲鍒?double. 榪欎簺綾誨瀷鐨勪簩榪涘埗琛ㄨ揪寮忔槸涓嶅悓鐨? 瑕佸皢鏁存暟 9 杞崲鍒?鍙岀簿搴︽暣鏁?9, static_cast 闇瑕佹紜湴涓哄弻綺懼害鏁存暟 d 琛ヨ凍姣旂壒浣? 鍏剁粨鏋滀負(fù) 9.0. 鑰宺einterpret_cast 鐨勮涓哄嵈涓嶅悓: </P> <P>    int n=9;<BR>    double d=reinterpret_cast<double & > (n); </P> <P>    榪欐, 緇撴灉鏈夋墍涓嶅悓. 鍦ㄨ繘琛岃綆椾互鍚? d 鍖呭惈鏃犵敤鍊? 榪欐槸鍥犱負(fù) reinterpret_cast 浠呬粎鏄鍒?n 鐨勬瘮鐗逛綅鍒?d, 娌℃湁榪涜蹇呰鐨勫垎鏋? </P><img src ="http://www.shnenglu.com/inwind/aggbug/1585.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/inwind/" target="_blank">inwind</a> 2005-12-07 10:50 <a href="http://www.shnenglu.com/inwind/articles/1585.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://www.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.fc117.cn" target="_blank">日本精品久久久久影院日本 </a>| <a href="http://www.aijialicai.com.cn" target="_blank">日韩人妻无码精品久久久不卡</a>| <a href="http://www.jsjingkou.cn" target="_blank">日本高清无卡码一区二区久久 </a>| <a href="http://www.gbpa.cn" target="_blank">久久久亚洲精品蜜桃臀 </a>| <a href="http://www.zxk2008bj.cn" target="_blank">久久精品国产亚洲AV高清热</a>| <a href="http://www.jshzyj.cn" target="_blank">亚洲精品国产成人99久久</a>| <a href="http://www.cynh.net.cn" target="_blank">午夜精品久久久久</a>| <a href="http://www.yx177.cn" target="_blank">四虎国产精品免费久久久</a>| <a href="http://www.tst5.cn" target="_blank">亚洲αv久久久噜噜噜噜噜</a>| <a href="http://www.nxol.net.cn" target="_blank">久久精品成人</a>| <a href="http://www.xeqw.cn" target="_blank">国产福利电影一区二区三区久久老子无码午夜伦不 </a>| <a href="http://www.vgunu.cn" target="_blank">久久综合久久性久99毛片</a>| <a href="http://www.90734.com.cn" target="_blank">精品久久久久久久久免费影院</a>| <a href="http://www.one-8.cn" target="_blank">国产A级毛片久久久精品毛片</a>| <a href="http://www.deografenny.com.cn" target="_blank">国产免费久久精品丫丫</a>| <a href="http://www.zwdl.com.cn" target="_blank">欧美黑人激情性久久</a>| <a href="http://www.91368.com.cn" target="_blank">久久精品国产精品亚洲精品</a>| <a href="http://www.uzijav.cn" target="_blank">国产精品一区二区久久不卡</a>| <a href="http://www.qingjian8.cn" target="_blank">人妻精品久久久久中文字幕69 </a>| <a href="http://www.shaikr.cn" target="_blank">久久久久亚洲AV综合波多野结衣</a>| <a href="http://www.dnn.org.cn" target="_blank">亚洲精品乱码久久久久久自慰</a>| <a href="http://www.link133.cn" target="_blank">狠狠综合久久综合中文88</a>| <a href="http://www.hardwareman.cn" target="_blank">久久777国产线看观看精品</a>| <a href="http://www.91chd.cn" target="_blank">伊人热热久久原色播放www</a>| <a href="http://www.zesf.com.cn" target="_blank">亚洲国产成人久久综合碰</a>| <a href="http://www.bqtao.cn" target="_blank">狠狠色婷婷综合天天久久丁香</a>| <a href="http://www.haolepay.cn" target="_blank">久久久久久国产精品美女 </a>| <a href="http://www.robuts.com.cn" target="_blank">国产午夜精品久久久久九九</a>| <a href="http://www.mdz8.cn" target="_blank">波多野结衣久久一区二区</a>| <a href="http://www.ynymdp.cn" target="_blank">国内精品久久久久久久久</a>| <a href="http://www.z9432.cn" target="_blank">国产精品久久成人影院</a>| <a href="http://www.anglein.cn" target="_blank">日本精品久久久久中文字幕</a>| <a href="http://www.8806699.cn" target="_blank">性欧美丰满熟妇XXXX性久久久</a>| <a href="http://www.zhaoyang-db.com.cn" target="_blank">精品一久久香蕉国产线看播放 </a>| <a href="http://www.pyspiderking.cn" target="_blank">国产高潮久久免费观看</a>| <a href="http://www.matchweb.cn" target="_blank">久久精品国产亚洲欧美</a>| <a href="http://www.eobt.cn" target="_blank">成人久久综合网</a>| <a href="http://www.cczone.cn" target="_blank">Xx性欧美肥妇精品久久久久久</a>| <a href="http://www.3ponline.com.cn" target="_blank">久久精品国产精品亚洲精品</a>| <a href="http://www.manour.cn" target="_blank">97久久精品午夜一区二区</a>| <a href="http://www.ndali.cn" target="_blank">久久精品国产亚洲沈樵</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>