锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 鍑芥暟瀵硅薄涓庡嚱鏁版寚閽堢浉姣旇緝鏈変袱涓柟闈㈢殑浼樼偣錛氶鍏堝鏋滆閲嶈澆鐨勮皟鐢ㄦ搷浣滅鏄痠nline鍑芥暟鍒欑紪璇戝櫒鑳藉鎵ц鍐呰仈緙栬瘧錛屾彁渚涘彲鑳界殑鎬ц兘濂藉錛涘叾嬈″嚱鏁板璞″彲浠ユ嫢鏈変換鎰忔暟鐩殑棰濆鏁版嵁錛岀敤榪欎簺鏁版嵁鍙互緙撳啿緇撴灉錛屼篃鍙互緙撳啿鏈夊姪浜庡綋鍓嶆搷浣滅殑鏁版嵁銆?/P>
鍑芥暟瀵硅薄鏄竴涓被錛屽畠閲嶈澆浜嗗嚱鏁拌皟鐢ㄦ搷浣滅operator() ,璇ユ搷浣滅灝佽浜嗕竴涓嚱鏁扮殑鍔熻兘銆傚吀鍨嬫儏鍐典笅鍑芥暟瀵硅薄琚綔涓哄疄鍙備紶閫掔粰娉涘瀷綆楁硶錛屽綋鐒舵垜浠篃鍙互瀹氫箟鐙珛鐨勫嚱鏁板璞″疄渚嬨?/P>
鏉ョ湅涓嬮潰鐨勪簩涓緥瀛愶細(xì) 姣旇緝鐞嗚В浼?xì)鏇村ソ浜涘Q?/P>
#include<vector> // function object that adds the value with which it is initialized // the ``function call'' for the element adds the value int main() // insert elements from 1 to 9 PRINT_ELEMENTS(coll,"initialized: "); // add value 10 to each element PRINT_ELEMENTS(coll,"after adding 10: "); // add value of first element to each element PRINT_ELEMENTS(coll,"after adding first element: "); 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: (T) expression // cast expression to be of type T 浜屻?C++鐨勫洓縐嶅己鍒惰漿鍨嬪艦寮忥細(xì) 銆銆C++ 鍚屾椂鎻愪緵浜嗗洓縐嶆柊鐨勫己鍒惰漿鍨嬪艦寮忥紙閫氬父縐頒負(fù)鏂伴鏍肩殑鎴?C++ 椋庢牸鐨勫己鍒惰漿鍨嬶級錛? 銆銆姣忎竴縐嶉傜敤浜庣壒瀹氱殑鐩殑錛? 銆銆dynamic_cast 涓昏鐢ㄤ簬鎵ц鈥滃畨鍏ㄧ殑鍚戜笅杞瀷錛坰afe downcasting錛夆濓紝涔熷氨鏄錛岃紜畾涓涓璞℃槸鍚︽槸涓涓戶鎵夸綋緋諱腑鐨勪竴涓壒瀹氱被鍨嬨傚畠鏄敮涓涓嶈兘鐢ㄦ棫椋庢牸璇硶鎵ц鐨勫己鍒惰漿鍨嬶紝涔熸槸鍞竴鍙兘鏈夐噸澶ц繍琛屾椂浠d環(huán)鐨勫己鍒惰漿鍨嬨?BR> 銆銆 reinterpret_cast 鏄壒鎰忕敤浜庡簳灞傜殑寮哄埗杞瀷錛屽鑷村疄鐜頒緷璧栵紙implementation-dependent錛夛紙灝辨槸璇達(dá)紝涓嶅彲縐繪錛夌殑緇撴灉錛屼緥濡傦紝灝嗕竴涓寚閽堣漿鍨嬩負(fù)涓涓暣鏁般傝繖鏍風(fēng)殑寮哄埗杞瀷鍦ㄥ簳灞備唬鐮佷互澶栧簲璇ユ瀬涓虹綍瑙併?BR>銆銆 == class B { ... }; void f(B* pb) 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. 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. 鍗砫ynamic_cast鍙敤浜庣戶鎵夸綋緋諱腑鐨勫悜涓嬭漿鍨嬶紝鍗沖皢鍩虹被鎸囬拡杞崲涓烘淳鐢熺被鎸囬拡錛屾瘮static_cast鏇翠弗鏍兼洿瀹夊叏銆俤ynamic_cast鍦ㄦ墽琛屾晥鐜囦笂姣攕tatic_cast瑕佸樊涓浜?浣唖tatic_cast鍦ㄦ洿瀹戒笂鑼冨洿鍐呭彲浠ュ畬鎴愭槧灝?榪欑涓嶅姞闄愬埗鐨勬槧灝勪即闅忕潃涓嶅畨鍏ㄦ?static_cast瑕嗙洊鐨勫彉鎹㈢被鍨嬮櫎綾誨眰嬈$殑闈欐佸鑸互澶?榪樺寘鎷棤鏄犲皠鍙樻崲,紿勫寲鍙樻崲(榪欑鍙樻崲浼?xì)瀵艰嚧瀵硅薄鍒囩?涓㈠け淇℃伅),鐢╒OID*鐨勫己鍒跺彉鎹?闅愬紡綾誨瀷鍙樻崲絳?.. reinterpret_cast鏄負(fù)浜嗘槧灝勫埌涓涓畬鍏ㄤ笉鍚岀被鍨嬬殑鎰忔?榪欎釜鍏抽敭璇嶅湪鎴戜滑闇瑕佹妸綾誨瀷鏄犲皠鍥炲師鏈夌被鍨嬫椂鐢ㄥ埌瀹?鎴戜滑鏄犲皠鍒扮殑綾誨瀷浠呬粎鏄負(fù)浜嗘晠寮勭巹铏氬拰鍏朵粬鐩殑,榪欐槸鎵鏈夋槧灝勪腑鏈鍗遍櫓鐨?(榪欏彞璇濇槸C++緙栫▼鎬濇兂涓殑鍘熻瘽) static_cast 鍜?reinterpret_cast 鎿嶄綔絎︿慨鏀逛簡鎿嶄綔鏁扮被鍨? 瀹冧滑涓嶆槸浜掗嗙殑; static_cast 鍦ㄧ紪璇戞椂浣跨敤綾誨瀷淇℃伅鎵ц杞崲, 鍦ㄨ漿鎹㈡墽琛屽繀瑕佺殑媯嫻?璇稿鎸囬拡瓚婄晫璁$畻, 綾誨瀷媯鏌?. 鍏舵搷浣滄暟鐩稿鏄畨鍏ㄧ殑. 鍙︿竴鏂歸潰, reinterpret_cast 浠呬粎鏄噸鏂拌В閲婁簡緇欏嚭鐨勫璞$殑姣旂壒妯″瀷鑰屾病鏈夎繘琛屼簩榪涘埗杞崲, 渚嬪瓙濡備笅: int n=9; double d=static_cast < double > (n); 涓婇潰鐨勪緥瀛愪腑, 鎴戜滑灝嗕竴涓彉閲忎粠 int 杞崲鍒?double. 榪欎簺綾誨瀷鐨勪簩榪涘埗琛ㄨ揪寮忔槸涓嶅悓鐨? 瑕佸皢鏁存暟 9 杞崲鍒?鍙岀簿搴︽暣鏁?9, static_cast 闇瑕佹紜湴涓哄弻綺懼害鏁存暟 d 琛ヨ凍姣旂壒浣? 鍏剁粨鏋滀負(fù) 9.0. 鑰宺einterpret_cast 鐨勮涓哄嵈涓嶅悓: int n=9; 榪欐, 緇撴灉鏈夋墍涓嶅悓. 鍦ㄨ繘琛岃綆椾互鍚? d 鍖呭惈鏃犵敤鍊? 榪欐槸鍥犱負(fù) reinterpret_cast 浠呬粎鏄鍒?n 鐨勬瘮鐗逛綅鍒?d, 娌℃湁榪涜蹇呰鐨勫垎鏋?
涓夈佸皬蹇冩垚鍛樺彉閲忕殑寮曠敤浼犻掞紝闃叉瀵瑰唴瀛樼殑澶氭閲婃斁
鎬諱箣錛屾敞鎰忕畻娉曡璁★紝灝忓績鍐呭瓨鍒嗛厤銆傞渶瑕佸姞寮?/P>
]]>
2銆傛寚閽堝彉閲忔槸鏈夊瓨鍌ㄧ┖闂寸殑錛涜屾暟緇勫悕浠呬粎鏄竴涓爣鍙鳳紝娌℃湁瀹為檯瀛樺偍絀洪棿錛屽崟鍗曚竴涓暟緇勫悕灝卞彧鑳借〃紺鴻鏁扮粍鐨勭1涓厓绱犵殑鍦板潃銆俰nt a[10]; 瑙勫畾&a灝辯瓑浜?amp;a[0]鎴栬卆 .
3銆備緥濡?char str[]= "hello world"鍜宑har *p = "hello world"涓紝鏁扮粍str鏄厛鍒嗛厤緇欎粬鍏冪礌涓暟涓唴瀛橈紝鐒跺悗灝嗗悗闈㈢殑瀛楃涓插鍒剁粰榪欎釜絀洪棿錛堟敞鎰忥紝姝ゆ椂搴旇鑰冭檻\0瀛楃錛夛紱鑰宲鐨勫緩绔嬭繃紼嬫槸鍏堝湪闈欐佸瓨鍌ㄥ尯寤虹珛甯稿瓧絎︿覆"hello world\0"錛岀劧鍚庡皢p鎸囧悜榪欎釜甯稿瓧絎︿覆銆傛墍浠ユ暟緇剆tr涓厓绱犵殑鍐呭鍙互閫氳繃閲嶆柊璧嬪兼敼鍙橈紝鑰宲鎸囧悜鐨勫唴瀹逛笉鑳芥敼鍙樸?img src ="http://m.shnenglu.com/inwind/aggbug/1958.html" width = "1" height = "1" />
]]>
]]>
鎴戝啓涓嬩簡濡備笅浠g爜錛?BR>
{
int i = 3;
return a+b+i;
}
int main()
{
int a = 1,b=2;
int result ;
result = fun(1,2);
return result;
}
闈炲父綆鍗曘傚弽姹囩紪鍚?Debug鐗?鍙樻垚榪欐牱
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錛屽氨鍙互鐩存帴鐪嬪埌鍑芥暟榪斿洖鍊間簡錛?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灝卞彲浠ヨ繑鍥炰簡銆?BR>
閭e鏋滄敼鍙樺嚱鏁扮殑榪斿洖鍦板潃浼?xì)鎬庢牱錛?BR>ok,鎴戜滑淇敼涓涓嬩唬鐮侊細(xì)
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琚皟鐢ㄤ簡銆傝繖灝辨槸Buffer overrun(緙撳啿婧㈠嚭)鎵鍋氱殑浜嬫儏鍚с?BR>
5.鏈鍚庝竴姝ワ紝璋冪敤鑰呰皟鏁村爢鏍堟寚閽?/STRONG>
call @ILT+5(fun) (0040100a)
add esp,8
涓轟粈涔堣璋冩暣鍛紝鍥犱負(fù)璋冪敤涔嬪墠push涓や釜鍙傛暟榪涘叆鏍堬紝鐜板湪瑕佹仮澶嶅畠
mov dword ptr [ebp-0Ch],eax
榪欏彞璇濆氨鏄韓鐢ㄥ嚱鏁拌皟鐢ㄧ殑鏋滃疄浜?EAX淇濆瓨浜嗗嚱鏁扮殑榪斿洖鍊?
]]>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
class Sum {
int val;
public:
Sum(int i) :val(i) { }
//褰撳湪闇瑕乮nt鐨勫湴鏂癸紝Sum灝嗚嚜鍔ㄨ漿鎹負(fù)int綾誨瀷
//榪欓噷鏄負(fù)浜嗘柟渚縞out<<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;
class AddValue {
private:
int theValue; // the value to add
public:
// constructor initializes the value to add
AddValue(int v) : theValue(v) {
}
void operator() (int& elem) const {
elem += theValue;
}
};
{
list<int> coll;
for (int i=1; i<=9; ++i) {
coll.push_back(i);
}
for_each (coll.begin(), coll.end(), // range
AddValue(10)); // operation
for_each (coll.begin(), coll.end(), // range
AddValue(*coll.begin())); // operation
}
-------------------------------------------------------------------------
operator()涓殑鍙傛暟涓篶ontainer涓殑鍏冪礌
錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛嶏紞錛?BR>
鍙﹀鐨勫疄渚嬶細(xì)
Function Objects as Sorting Criteria // 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;
}
]]>
鍑芥暟椋庢牸錛團(tuán)unction-style錛夊己鍒惰漿鍨嬩嬌鐢ㄨ繖鏍風(fēng)殑璇硶錛?BR> T(expression) // cast expression to be of type T
榪欎袱縐嶅艦寮忎箣闂存病鏈夋湰璐ㄤ笂鐨勪笉鍚岋紝瀹冪函綺瑰氨鏄竴涓妸鎷彿鏀懼湪鍝殑闂銆傛垜鎶婅繖涓ょ褰㈠紡縐頒負(fù)鏃ч鏍鹼紙old-style錛夌殑寮哄埗杞瀷銆?
銆銆const_cast(expression)
銆銆dynamic_cast(expression)
銆銆reinterpret_cast(expression)
銆銆static_cast(expression)
static_cast 鍙互琚敤浜庡己鍒墮殣鍨嬭漿鎹紙渚嬪錛宯on-const 瀵硅薄杞瀷涓?const 瀵硅薄錛宨nt 杞瀷涓?double錛岀瓑絳夛級錛屽畠榪樺彲浠ョ敤浜庡緢澶氳繖鏍風(fēng)殑杞崲鐨勫弽鍚戣漿鎹紙渚嬪錛寁oid* 鎸囬拡杞瀷涓烘湁綾誨瀷鎸囬拡錛屽熀綾繪寚閽堣漿鍨嬩負(fù)媧劇敓綾繪寚閽堬級錛屼絾鏄畠涓嶈兘灝嗕竴涓?const 瀵硅薄杞瀷涓?non-const 瀵硅薄錛堝彧鏈?const_cast 鑳藉仛鍒幫級錛屽畠鏈鎺ヨ繎浜嶤-style鐨勮漿鎹€?BR>
銆銆 const_cast 涓鑸敤浜庡己鍒舵秷闄ゅ璞$殑甯擱噺鎬с傚畠鏄敮涓鑳藉仛鍒拌繖涓鐐圭殑 C++ 椋庢牸鐨勫己鍒惰漿鍨嬨?
銆銆鏃ч鏍肩殑寮哄埗杞瀷渚濈劧鍚堟硶錛屼絾鏄柊鐨勫艦寮忔洿鍙彇銆傞鍏堬紝鍦ㄤ唬鐮佷腑瀹冧滑鏇村鏄撹瘑鍒紙鏃犺鏄漢榪樻槸鍍?grep 榪欐牱鐨勫伐鍏烽兘鏄姝わ級錛岃繖鏍峰氨綆鍖栦簡鍦ㄤ唬鐮佷腑瀵繪壘綾誨瀷緋葷粺琚牬鍧忕殑鍦版柟鐨勮繃紼嬨傜浜岋紝鏇寸簿紜湴鎸囧畾姣忎竴涓己鍒惰漿鍨嬬殑鐩殑錛屼嬌寰楃紪璇戝櫒璇婃柇浣跨敤閿欒鎴愪負(fù)鍙兘銆備緥濡傦紝濡傛灉浣犺瘯鍥句嬌鐢ㄤ竴涓?const_cast 浠ュ鐨勬柊椋庢牸寮哄埗杞瀷鏉ユ秷闄ゅ父閲忔э紝浣犵殑浠g爜灝嗘棤娉曠紪璇戙?
== dynamic_cast .vs. static_cast
==
class D : public B { ... };
{
D* pd1 = dynamic_cast<D*>(pb);
D* pd2 = static_cast<D*>(pb);
}
==
== static_cast .vs. reinterpret_cast
==
double d=reinterpret_cast<double & > (n);
]]>