青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

C++ Programmer's Cookbook

{C++ 基礎(chǔ)} {C++ 高級(jí)} {C#界面,C++核心算法} {設(shè)計(jì)模式} {C#基礎(chǔ)}

C++ casting

Q: What are the C++ casting operators?

A: Casting means you change the representation of a variable by changing its type to a different one. In order to type-cast a simple object to another you use the traditional type casting operator. For example, to cast a floating point number of type 'double' to an integer of type 'int':

#include <typeinfo>

Code:

int i;
double d;

i = (int) d;
or also


Code:

i = int (d);
This is quite good for basic types that have standard defined conversions, however this operators can also been indiscriminately applied on classes and pointers to classes. ANSI-C++ standard has defined four new casting operators: 'reinterpret_cast', 'static_cast', 'dynamic_cast' and 'const_cast' in order to control these types of conversions between classes...


Code:
reinterpret_cast<new_type>(expression)
Code:
static_cast<new_type>(expression)
Code:
dynamic_cast<new_type>(expression)
Code:
const_cast<new_type>(expression)

'reinterpret_cast'

'reinterpret_cast' casts a pointer to any other type of pointer. It also allows casting from pointer to an integer type and vice versa.

This operator can cast pointers between non-related classed. The operation results is a simple binary copy of the value from a pointer to the other. The content pointed does not pass any kind of check nor transformation between types.

In the case that the copy is performed from a pointer to an integer, the interpretation of its content is system dependent and therefore any implementation is non portable. A pointer casted to an integer enough large to fully contain it can be casted back to a valid pointer.


Code:

class A {};
class B {};

A * a = new A;
B * b = reinterpret_cast<B *>(a);
'reinterpret_cast' treats all pointers exactly as traditional type-casting operators do.


'static_cast'

'static_cast' allows to perform any casting that can be implicitly performed as well as also the inverse cast (even if this is not allowed implicitly).

Applied to pointers to classes, that is to say that it allows to cast a pointer of a derived class to its base class (this is a valid conversion that can be implicitly performed) and can also perform the inverse: cast a base class to its derivated class.

In this last case the base class that is being casted is not checked to determine wether this is a complete class of the destination type or not.


Code:

class Base {};
class Derived : public Base {};

Base *a    = new Base;
Derived *b = static_cast<Derived *>(a);
'static_cast', aside from manipulating pointers to classes, can also be used to perform conversions explicitly defined in classes, as well as to perform standard conversions between fundamental types:


Code:

double d = 3.14159265;
int    i = static_cast<int>(d);


'dynamic_cast'

'dynamic_cast' is exclusively used with pointers and references to objects. It allows any type-casting that can be implicitly performed as well as the inverse one when used with polymorphic classes, however, unlike static_cast, dynamic_cast checks, in this last case, if the operation is valid. That is to say, it checks if the casting is going to return a valid complete object of the requested type.

Checking is performed during run-time execution. If the pointer being casted is not a pointer to a valid complete object of the requested type, the value returned is a 'NULL' pointer.


Code:

class Base { virtual dummy() {} };
class Derived : public Base {};

Base* b1 = new Derived;
Base* b2 = new Base;

Derived* d1 = dynamic_cast<Derived *>(b1);          // succeeds
Derived* d2 = dynamic_cast<Derived *>(b2);          // fails: returns 'NULL'
If the type-casting is performed to a reference type and this casting is not possible an exception of type 'bad_cast' is thrown:


Code:

class Base { virtual dummy() {} };
class Derived : public Base { };

Base* b1 = new Derived;
Base* b2 = new Base;

Derived d1 = dynamic_cast<Derived &*>(b1);          // succeeds
Derived d2 = dynamic_cast<Derived &*>(b2);          // fails: exception thrown


'const_cast'

This type of casting manipulates the const attribute of the passed object, either to be set or removed:


Code:

class C {};

const C *a = new C;

C *b = const_cast<C *>(a);
Neither of the other three new cast operators can modify the constness of an object.

Note: The 'const_cast' operator can also change the 'volatile' qualifier on a type.


typeid  得到類(lèi)對(duì)象或指針

typeid(*pb).name()   輸出對(duì)象名
 
typeid(pb).name()     輸出類(lèi)名

 

---------子類(lèi)向基類(lèi)私有或保護(hù)繼承的時(shí),可以轉(zhuǎn)化但是不能訪(fǎng)問(wèn)。 一般不進(jìn)行轉(zhuǎn)化。error 2443



------------------------------------------------------------------------------------
C++風(fēng)格的轉(zhuǎn)型運(yùn)算符小結(jié)

為了改正C中丑陋的轉(zhuǎn)型操作,C++中引入了四個(gè)新的轉(zhuǎn)型操作符,分別是:
dynamic_cast
const_cast
static_cast
reinterpret_cast

1.dynamic_cast
這個(gè)轉(zhuǎn)型操作符主要用在安全的向下轉(zhuǎn)型(safe downcasting)中,也就是從基類(lèi)指針/引用向派生類(lèi)指針/引用的轉(zhuǎn)型。例如:
Code: [View More of this Code] [View Even More of this Code] [View Less of this Code] [Select All of this Code]

class A {...};
class B:public A {...};
A* a = new B;
B* b;
b = dynamic_cast<B *> a;

當(dāng)你將dynamic_cast用在指針上時(shí),如果成功,就傳回一個(gè)轉(zhuǎn)型目標(biāo)的指針,如果失敗,則傳回null指針。所以用到dynamic_cast的時(shí)候必然會(huì)導(dǎo)致if-then-else的程序風(fēng)格,其中else就是用來(lái)檢測(cè)轉(zhuǎn)型失敗的情況([1]第39條)。例子如下:
Code: [View More of this Code] [View Even More of this Code] [View Less of this Code] [Select All of this Code]
#include <iostream>
using namespace std;

class A {
public:
 virtual void do_sth(){
  cout<<"aaa\n";
 }

};
class B : public A {
public:
 virtual void do_sth(){
  cout<<"bbb\n";
 }

};
class C : public A {
public:
 virtual void do_sth(){
  cout<<"ccc\n";
 }
 
};

int main(){
 A* a1 = new B;
 A* a2 = new C;
 B* b;

 if(b = dynamic_cast<B *>(a1))//轉(zhuǎn)換成功
  b->do_sth();
 else
  cout<<"error\n";
 
 if(b = dynamic_cast<B *>(a2))//轉(zhuǎn)換失敗
  b->do_sth();
 else
  cout<<"error\n";
}


2.const_cast
此轉(zhuǎn)型操作符用來(lái)將對(duì)象或指針的常量性(sonstness)轉(zhuǎn)型掉。例如:

const A * a1;
A * a2 = const_cast<A *> (a1);

需要注意的是,const_cast轉(zhuǎn)型并不總是成功的,當(dāng)遇到轉(zhuǎn)型的對(duì)象本身就是const的時(shí)候,那么將其常量性轉(zhuǎn)型,結(jié)果未定義。看一下下面的例子:
Code: [View More of this Code] [View Even More of this Code] [View Less of this Code] [Select All of this Code]

// constcast.cpp from [2]
#include <iostream>
using std::cout;

void change(const int * pt, int n);

int main()
{
    int pop1 = 38383;
    const int pop2 = 2000;

    cout << "pop1, pop2: " << pop1 << ", " << pop2 << '\n';
    change(&pop1, -1);
    change(&pop2, -1);
    cout << "pop1, pop2: " << pop1 << ", " << pop2 << '\n';

    return 0;
}

void change(const int * pt, int n)
{
    int * pc;
    if (n < 0)
    {
        pc = const_cast<int *>(pt);
        *pc = 100;
    }
}

輸出的結(jié)果是:
pop1, pop2: 38383, 2000
pop1, pop2: 100, 2000
可見(jiàn),pop2的值并沒(méi)有改變(有些編譯器會(huì)產(chǎn)生一個(gè)pop2的臨時(shí)變量,并將其地址值賦給pc。在C++標(biāo)準(zhǔn)中,這種情況下的行為是不確定的[2])。

3.static_cast
此轉(zhuǎn)型操作符用于內(nèi)建數(shù)據(jù)類(lèi)型之間的轉(zhuǎn)型。它與C的轉(zhuǎn)型操作最接近。當(dāng)沒(méi)有其他適當(dāng)?shù)霓D(zhuǎn)型操作符可用時(shí),就使用它。它可以將整型轉(zhuǎn)換為枚舉型,雙精度型轉(zhuǎn)換為整型,浮點(diǎn)型轉(zhuǎn)換為長(zhǎng)整型等等。例如:
Code: [View More of this Code] [View Even More of this Code] [View Less of this Code] [Select All of this Code]

    int n=9;
    double d = static_cast < double > (n);

上面的例子中,我們將一個(gè)變量從 int 轉(zhuǎn)換到 double. 這些類(lèi)型的二進(jìn)制表達(dá)式是不同的。要將整數(shù) 9 轉(zhuǎn)換到 雙精度整數(shù) 9,static_cast需要正確地為雙精度整數(shù) d 補(bǔ)足比特位。其結(jié)果為 9.0 。

4.reinterpret_cast
此轉(zhuǎn)型操作符的結(jié)果取決于編譯器,用于修改操作數(shù)類(lèi)型,非類(lèi)型安全的轉(zhuǎn)換符。舉例如下:
Code: [View More of this Code] [View Even More of this Code] [View Less of this Code] [Select All of this Code]

int main() { // from [2]
    struct dat { short a; short b;};
    long value = 0xA224B118;
    dat * pd = reinterpret_cast<dat *> (&value);
    cout << pd->a;   // display first 2 bytes of value
    return 0;
}

該例中將long型轉(zhuǎn)換成struct,但此代碼是不可移植的,在IBM兼容機(jī)和Mac機(jī)上的運(yùn)行結(jié)果完全不一樣,因?yàn)樗麄兇鎯?chǔ)字節(jié)的方式不一樣。
reinterpret_cast的使用要非常的謹(jǐn)慎,例如將3中的例子改寫(xiě)如下:
Code: [View More of this Code] [View Even More of this Code] [View Less of this Code] [Select All of this Code]

    int n=9;
    double d = reinterpret_cast<double & > (n);
  

這次,與3的結(jié)果有所不同。在進(jìn)行計(jì)算以后,d 包含無(wú)用值。這是因?yàn)?reinterpret_cast 僅僅是復(fù)制 n 的比特位到 d,沒(méi)有進(jìn)行必要的分析。

以上是我在學(xué)習(xí)這些轉(zhuǎn)型操作符一個(gè)小結(jié),如有不對(duì)之處,請(qǐng)各位不嗇賜教。
大家有興趣,可以去這里做一下有關(guān)這些轉(zhuǎn)型操作符的練習(xí)。

注:以上例子在 VC6 + Intel C++ Compiler 8.0 下編譯運(yùn)行通過(guò)(別忘了打開(kāi)RTTI,加參數(shù)/GR)。

參考文獻(xiàn):
[1] Effective C++ 中文版 Scott Meyers 侯捷譯
[2] C++ Primer Plus, 4th Edition, Stephen Prata
[3] STATIC_CAST VERSUS REINTERPRET_CAST(Topica轉(zhuǎn)載)


----------------------------------
這是More Effecitve C++里的第二條對(duì)類(lèi)型轉(zhuǎn)換講的很好,也很基礎(chǔ)好懂。
Item M2:盡量使用C++風(fēng)格的類(lèi)型轉(zhuǎn)換
仔細(xì)想想地位卑賤的類(lèi)型轉(zhuǎn)換功能(cast),其在程序設(shè)計(jì)中的地位就象goto語(yǔ)句一樣令人鄙視。但是它還不是無(wú)法令人忍受,因?yàn)楫?dāng)在某些緊要的關(guān)頭,類(lèi)型轉(zhuǎn)換還是必需的,這時(shí)它是一個(gè)必需品。
不過(guò)C風(fēng)格的類(lèi)型轉(zhuǎn)換并不代表所有的類(lèi)型轉(zhuǎn)換功能。
       一、來(lái)它們過(guò)于粗魯,能允許你在任何類(lèi)型之間進(jìn)行轉(zhuǎn)換。不過(guò)如果要進(jìn)行更精確的類(lèi)型轉(zhuǎn)換,這會(huì)是一個(gè)優(yōu)點(diǎn)。在這些類(lèi)型轉(zhuǎn)換中存在著巨大的不同,例如把一個(gè)指向 const對(duì)象的指針(pointer-to-const-object)轉(zhuǎn)換成指向非const對(duì)象的指針(pointer-to-non-const -object)(即一個(gè)僅僅去除const的類(lèi)型轉(zhuǎn)換),把一個(gè)指向基類(lèi)的指針轉(zhuǎn)換成指向子類(lèi)的指針(即完全改變對(duì)象類(lèi)型)。傳統(tǒng)的C風(fēng)格的類(lèi)型轉(zhuǎn)換不對(duì)上述兩種轉(zhuǎn)換進(jìn)行區(qū)分。(這一點(diǎn)也不令人驚訝,因?yàn)镃風(fēng)格的類(lèi)型轉(zhuǎn)換是為C語(yǔ)言設(shè)計(jì)的,而不是為C++語(yǔ)言設(shè)計(jì)的)。
      二、來(lái)C 風(fēng)格的類(lèi)型轉(zhuǎn)換在程序語(yǔ)句中難以識(shí)別。在語(yǔ)法上,類(lèi)型轉(zhuǎn)換由圓括號(hào)和標(biāo)識(shí)符組成,而這些可以用在C++中的任何地方。這使得回答象這樣一個(gè)最基本的有關(guān)類(lèi)型轉(zhuǎn)換的問(wèn)題變得很困難:“在這個(gè)程序中是否使用了類(lèi)型轉(zhuǎn)換?”。這是因?yàn)槿斯ら喿x很可能忽略了類(lèi)型轉(zhuǎn)換的語(yǔ)句,而利用象grep的工具程序也不能從語(yǔ)句構(gòu)成上區(qū)分出它們來(lái)。
C++通過(guò)引進(jìn)四個(gè)新的類(lèi)型轉(zhuǎn)換操作符克服了C風(fēng)格類(lèi)型轉(zhuǎn)換的缺點(diǎn),這四個(gè)操作符是, static_cast, const_cast, dynamic_cast, 和reinterpret_cast。在大多數(shù)情況下,對(duì)于這些操作符你只需要知道原來(lái)你習(xí)慣于這樣寫(xiě),
(type) expression
而現(xiàn)在你總應(yīng)該這樣寫(xiě):
static_cast<type>(expression)
例如,假設(shè)你想把一個(gè)int轉(zhuǎn)換成double,以便讓包含int類(lèi)型變量的表達(dá)式產(chǎn)生出浮點(diǎn)數(shù)值的結(jié)果。如果用C風(fēng)格的類(lèi)型轉(zhuǎn)換,你能這樣寫(xiě):
int firstNumber, secondNumber;
...
double result = ((double)firstNumber)/secondNumber;
如果用上述新的類(lèi)型轉(zhuǎn)換方法,你應(yīng)該這樣寫(xiě):
double result = static_cast<double>(firstNumber)/secondNumber;
這樣的類(lèi)型轉(zhuǎn)換不論是對(duì)人工還是對(duì)程序都很容易識(shí)別。
static_cast 在功能上基本上與C風(fēng)格的類(lèi)型轉(zhuǎn)換一樣強(qiáng)大,含義也一樣。它也有功能上限制。例如,你不能用static_cast象用C風(fēng)格的類(lèi)型轉(zhuǎn)換一樣把 struct轉(zhuǎn)換成int類(lèi)型或者把double類(lèi)型轉(zhuǎn)換成指針類(lèi)型,另外,static_cast不能從表達(dá)式中去除const屬性,因?yàn)榱硪粋€(gè)新的類(lèi)型轉(zhuǎn)換操作符const_cast有這樣的功能。
其它新的C++類(lèi)型轉(zhuǎn)換操作符被用在需要更多限制的地方。const_cast用于類(lèi)型轉(zhuǎn)換掉表達(dá)式的const或volatileness屬性。通過(guò)使用const_cast,你向人們和編譯器強(qiáng)調(diào)你通過(guò)類(lèi)型轉(zhuǎn)換想做的只是改變一些東西的 constness或者volatileness屬性。這個(gè)含義被編譯器所約束。如果你試圖使用const_cast來(lái)完成修改constness 或者volatileness屬性之外的事情,你的類(lèi)型轉(zhuǎn)換將被拒絕。下面是一些例子:
class Widget { ... };
class SpecialWidget: public Widget { ... };
void update(SpecialWidget *psw);
SpecialWidget sw; // sw 是一個(gè)非const 對(duì)象。
const SpecialWidget& csw = sw; // csw 是sw的一個(gè)引用
// 它是一個(gè)const 對(duì)象
update(&csw); // 錯(cuò)誤!不能傳遞一個(gè)const SpecialWidget* 變量
// 給一個(gè)處理SpecialWidget*類(lèi)型變量的函數(shù)
update(const_cast<SpecialWidget*>(&csw));
// 正確,csw的const被顯示地轉(zhuǎn)換掉(
// csw和sw兩個(gè)變量值在update
//函數(shù)中能被更新)
update((SpecialWidget*)&csw);
// 同上,但用了一個(gè)更難識(shí)別
//的C風(fēng)格的類(lèi)型轉(zhuǎn)換
Widget *pw = new SpecialWidget;
update(pw); // 錯(cuò)誤!pw的類(lèi)型是Widget*,但是
// update函數(shù)處理的是SpecialWidget*類(lèi)型
update(const_cast<SpecialWidget*>(pw));
// 錯(cuò)誤!const_cast僅能被用在影響
// constness or volatileness的地方上。,
// 不能用在向繼承子類(lèi)進(jìn)行類(lèi)型轉(zhuǎn)換?br> 到目前為止,const_cast最普通的用途就是轉(zhuǎn)換掉對(duì)象的const屬性。
第二種特殊的類(lèi)型轉(zhuǎn)換符是dynamic_cast,它被用于安全地沿著類(lèi)的繼承關(guān)系向下進(jìn)行類(lèi)型轉(zhuǎn)換。這就是說(shuō),你能用dynamic_cast把指向基類(lèi)的指針或引用轉(zhuǎn)換成指向其派生類(lèi)或其兄弟類(lèi)的指針或引用,而且你能知道轉(zhuǎn)換是否成功。失敗的轉(zhuǎn)換將返回空指針(當(dāng)對(duì)指針進(jìn)行類(lèi)型轉(zhuǎn)換時(shí))或者拋出異常(當(dāng)對(duì)引用進(jìn)行類(lèi)型轉(zhuǎn)換時(shí)):
Widget *pw;
...
update(dynamic_cast<SpecialWidget*>(pw));
// 正確,傳遞給update函數(shù)一個(gè)指針
// 是指向變量類(lèi)型為SpecialWidget的pw的指針
// 如果pw確實(shí)指向一個(gè)對(duì)象,
// 否則傳遞過(guò)去的將使空指針。
void updateViaRef(SpecialWidget& rsw);
updateViaRef(dynamic_cast<SpecialWidget&>(*pw));
//正確。傳遞給updateViaRef函數(shù)
// SpecialWidget pw 指針,如果pw
// 確實(shí)指向了某個(gè)對(duì)象
// 否則將拋出異常
dynamic_casts在幫助你瀏覽繼承層次上是有限制的。它不能被用于缺乏虛函數(shù)的類(lèi)型上(參見(jiàn)條款M24),也不能用它來(lái)轉(zhuǎn)換掉constness:
int firstNumber, secondNumber;
...
double result = dynamic_cast<double>(firstNumber)/secondNumber;
// 錯(cuò)誤!沒(méi)有繼承關(guān)系
const SpecialWidget sw;
...
update(dynamic_cast<SpecialWidget*>(&sw));
// 錯(cuò)誤! dynamic_cast不能轉(zhuǎn)換
// 掉const。
如你想在沒(méi)有繼承關(guān)系的類(lèi)型中進(jìn)行轉(zhuǎn)換,你可能想到static_cast。如果是為了去除const,你總得用const_cast。
這四個(gè)類(lèi)型轉(zhuǎn)換符中的最后一個(gè)是reinterpret_cast。使用這個(gè)操作符的類(lèi)型轉(zhuǎn)換,其的轉(zhuǎn)換結(jié)果幾乎都是執(zhí)行期定義(implementation-defined)。因此,使用reinterpret_casts的代碼很難移植。
reinterpret_casts的最普通的用途就是在函數(shù)指針類(lèi)型之間進(jìn)行轉(zhuǎn)換。例如,假設(shè)你有一個(gè)函數(shù)指針數(shù)組:
typedef void (*FuncPtr)(); // FuncPtr is 一個(gè)指向函數(shù)
// 的指針,該函數(shù)沒(méi)有參數(shù)
// 返回值類(lèi)型為void
FuncPtr funcPtrArray[10]; // funcPtrArray 是一個(gè)能容納
// 10個(gè)FuncPtrs指針的數(shù)組
讓我們假設(shè)你希望(因?yàn)槟承┠涿畹脑颍┌岩粋€(gè)指向下面函數(shù)的指針存入funcPtrArray數(shù)組:
int doSomething();
你不能不經(jīng)過(guò)類(lèi)型轉(zhuǎn)換而直接去做,因?yàn)閐oSomething函數(shù)對(duì)于funcPtrArray數(shù)組來(lái)說(shuō)有一個(gè)錯(cuò)誤的類(lèi)型。在FuncPtrArray數(shù)組里的函數(shù)返回值是void類(lèi)型,而doSomething函數(shù)返回值是int類(lèi)型。
funcPtrArray[0] = &doSomething; // 錯(cuò)誤!類(lèi)型不匹配
reinterpret_cast可以讓你迫使編譯器以你的方法去看待它們:
funcPtrArray[0] = // this compiles
reinterpret_cast<FuncPtr>(&doSomething);
轉(zhuǎn)換函數(shù)指針的代碼是不可移植的(C++不保證所有的函數(shù)指針都被用一樣的方法表示),在一些情況下這樣的轉(zhuǎn)換會(huì)產(chǎn)生不正確的結(jié)果(參見(jiàn)條款M31),所以你應(yīng)該避免轉(zhuǎn)換函數(shù)指針類(lèi)型,除非你處于著背水一戰(zhàn)和尖刀架喉的危急時(shí)刻。一把鋒利的刀。一把非常鋒利的刀。
如果你使用的編譯器缺乏對(duì)新的類(lèi)型轉(zhuǎn)換方式的支持,你可以用傳統(tǒng)的類(lèi)型轉(zhuǎn)換方法代替static_cast, const_cast, 以及reinterpret_cast。也可以用下面的宏替換來(lái)模擬新的類(lèi)型轉(zhuǎn)換語(yǔ)法:
#define static_cast(TYPE,EXPR) ((TYPE)(EXPR))
#define const_cast(TYPE,EXPR) ((TYPE)(EXPR))
#define reinterpret_cast(TYPE,EXPR) ((TYPE)(EXPR))
你可以象這樣使用使用:
double result = static_cast(double, firstNumber)/secondNumber;
update(const_cast(SpecialWidget*, &sw));
funcPtrArray[0] = reinterpret_cast(FuncPtr, &doSomething);
這些模擬不會(huì)象真實(shí)的操作符一樣安全,但是當(dāng)你的編譯器可以支持新的的類(lèi)型轉(zhuǎn)換時(shí),它們可以簡(jiǎn)化你把代碼升級(jí)的過(guò)程。
沒(méi)有一個(gè)容易的方法來(lái)模擬dynamic_cast的操作,但是很多函數(shù)庫(kù)提供了函數(shù),安全地在派生類(lèi)與基類(lèi)之間進(jìn)行類(lèi)型轉(zhuǎn)換。如果你沒(méi)有這些函數(shù)而你有必須進(jìn)行這樣的類(lèi)型轉(zhuǎn)換,你也可以回到C風(fēng)格的類(lèi)型轉(zhuǎn)換方法上,但是這樣的話(huà)你將不能獲知類(lèi)型轉(zhuǎn)換是否失敗。當(dāng)然,你也可以定義一個(gè)宏來(lái)模擬 dynamic_cast的功能,就象模擬其它的類(lèi)型轉(zhuǎn)換一樣:
#define dynamic_cast(TYPE,EXPR) (TYPE)(EXPR)
請(qǐng)記住,這個(gè)模擬并不能完全實(shí)現(xiàn)dynamic_cast的功能,它沒(méi)有辦法知道轉(zhuǎn)換是否失敗。
我知道,是的,我知道,新的類(lèi)型轉(zhuǎn)換操作符不是很美觀而且用鍵盤(pán)鍵入也很麻煩。如果你發(fā)現(xiàn)它們看上去實(shí)在令人討厭,C風(fēng)格的類(lèi)型轉(zhuǎn)換還可以繼續(xù)使用并且合法。然而,正是因?yàn)樾碌念?lèi)型轉(zhuǎn)換符缺乏美感才能使它彌補(bǔ)了在含義精確性和可辨認(rèn)性上的缺點(diǎn)。并且,使用新類(lèi)型轉(zhuǎn)換符的程序更容易被解析(不論是對(duì)人工還是對(duì)于工具程序),它們?cè)试S編譯器檢測(cè)出原來(lái)不能發(fā)現(xiàn)的錯(cuò)誤。這些都是放棄C風(fēng)格類(lèi)型轉(zhuǎn)換方法的強(qiáng)有力的理由。還有第三個(gè)理由:也許讓類(lèi)型轉(zhuǎn)換符不美觀和鍵入麻煩是一件好事。

posted on 2005-11-09 13:02 夢(mèng)在天涯 閱讀(1942) 評(píng)論(2)  編輯 收藏 引用 所屬分類(lèi): CPlusPlus

評(píng)論

# re: C++ casting 2006-09-29 12:30 一雨田

typeid只能得到類(lèi)名,不可以得到對(duì)象名。  回復(fù)  更多評(píng)論   

# re: C++ casting 2011-07-05 22:24 renwotao

可以得到對(duì)象名typeid(類(lèi)名).name()@一雨田
  回復(fù)  更多評(píng)論   

公告

EMail:itech001#126.com

導(dǎo)航

統(tǒng)計(jì)

  • 隨筆 - 461
  • 文章 - 4
  • 評(píng)論 - 746
  • 引用 - 0

常用鏈接

隨筆分類(lèi)

隨筆檔案

收藏夾

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

積分與排名

  • 積分 - 1815239
  • 排名 - 5

最新評(píng)論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
      <noscript id="pjuwb"></noscript>
            <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
              <dd id="pjuwb"></dd>
              <abbr id="pjuwb"></abbr>
              亚洲精品之草原avav久久| 欧美福利一区二区| 亚洲高清网站| 亚洲在线观看视频| 亚洲日本一区二区| 久久一区二区三区国产精品| 久久九九全国免费精品观看| 国产农村妇女精品一二区| 亚洲午夜91| 香蕉视频成人在线观看| 欧美日韩国产区一| 亚洲美女网站| 亚洲一二三区在线| 国产精品久久久99| 午夜精品国产| 欧美不卡在线| 欧美成人精品不卡视频在线观看 | 艳妇臀荡乳欲伦亚洲一区| 日韩视频免费在线| 欧美片第1页综合| 9久re热视频在线精品| 亚洲性人人天天夜夜摸| 国产精品女主播| 欧美一级日韩一级| 免费日本视频一区| 亚洲乱码视频| 国产精品蜜臀在线观看| 欧美亚洲免费| 欧美超级免费视 在线| 日韩亚洲国产精品| 国产精品三区www17con| 欧美淫片网站| 亚洲成人资源网| 欧美国产一区二区| 一个色综合av| 久久乐国产精品| 亚洲欧洲精品一区二区三区不卡| 欧美精品日日鲁夜夜添| 亚洲一区三区在线观看| 奶水喷射视频一区| 一本综合精品| 国产夜色精品一区二区av| 久久精品国产99| 亚洲人精品午夜| 欧美一区二区性| 91久久精品一区二区别| 国产精品久久久久aaaa| 久久国产婷婷国产香蕉| 亚洲国产精品悠悠久久琪琪| 午夜视频久久久久久| 亚洲国产精品第一区二区三区| 欧美日韩国产综合在线| 欧美在线亚洲在线| 999亚洲国产精| 久久亚洲精品中文字幕冲田杏梨| 亚洲精品自在久久| 国产日韩一区二区| 欧美精选在线| 久久精品视频免费| 亚洲精品在线观看免费| 老牛国产精品一区的观看方式| 亚洲少妇在线| 亚洲国产精品一区二区www| 国产精品入口福利| 欧美国产大片| 欧美在线一区二区三区| 一本色道久久综合亚洲91| 欧美不卡福利| 久久久精品日韩| 性欧美xxxx视频在线观看| 99精品免费网| 91久久久亚洲精品| 激情成人综合| 国产精品资源在线观看| 欧美日韩一区二区三区在线视频 | 欧美bbbxxxxx| 久久精品二区| 亚洲综合国产| 夜夜爽www精品| 91久久极品少妇xxxxⅹ软件| 久久综合九九| 久久国产精品久久国产精品| 亚洲伊人观看| 99精品欧美| 亚洲精品欧美日韩专区| 在线日韩电影| 激情欧美日韩| 韩国av一区二区| 国产亚洲欧美日韩在线一区| 国产精品日本| 国产精品亚洲不卡a| 国产精品狼人久久影院观看方式| 欧美日韩国产综合久久| 欧美日韩视频在线一区二区 | 一区二区三区在线观看国产| 国产欧美日韩另类视频免费观看| 国产精品视频久久| 国产精品爽爽爽| 国产精品一级在线| 国产精品专区一| 国产亚洲精品久久飘花| 国产欧美日韩综合一区在线观看 | 亚洲一二三区在线| 亚洲天堂av电影| 中文精品视频| 亚洲视频在线看| 亚洲影视在线播放| 午夜精品久久| 久久精品在这里| 噜噜噜噜噜久久久久久91| 欧美va天堂va视频va在线| 欧美大尺度在线观看| 亚洲夫妻自拍| 日韩视频一区二区三区在线播放免费观看| 最新日韩在线视频| 99国产精品99久久久久久粉嫩| 一本色道久久综合亚洲二区三区| 亚洲婷婷在线| 欧美一区二区视频免费观看| 久久国内精品视频| 另类春色校园亚洲| 欧美激情国产日韩| 欧美日韩在线播放| 国产精品久久久久久久7电影| 国产精品系列在线| 黄色一区二区在线| 99re66热这里只有精品4| 亚洲特级毛片| 久久久水蜜桃| 亚洲日本乱码在线观看| 亚洲午夜三级在线| 久久久99国产精品免费| 欧美美女福利视频| 国产午夜精品视频| 亚洲黄色免费| 亚洲欧美国产77777| 欧美在线|欧美| 欧美国产视频日韩| 亚洲视频在线观看视频| 久久精品人人做人人爽电影蜜月| 欧美精品一区在线发布| 国产视频亚洲| 一区二区91| 老巨人导航500精品| 一本久久a久久精品亚洲| 久久精品久久综合| 欧美三级日本三级少妇99| 国产欧美在线看| 99精品视频免费观看视频| 久久精品系列| 99视频日韩| 女人色偷偷aa久久天堂| 国产精品美女久久久久av超清| 亚洲第一毛片| 久久国产精品久久w女人spa| 亚洲三级免费电影| 久久久免费精品| 国产欧美一区二区三区视频| 一区二区三区四区五区精品视频| 久久久精品免费视频| 在线综合视频| 欧美激情一区二区三区四区| 国产一区二区三区久久久久久久久| 中文有码久久| 欧美激情四色| 久久久久综合| 国产揄拍国内精品对白| 亚洲欧美日韩成人高清在线一区| 亚洲成色777777在线观看影院| 亚洲欧美日韩精品| 欧美无乱码久久久免费午夜一区| 亚洲国产一区二区三区在线播 | 久久精品国产欧美亚洲人人爽| 亚洲国产岛国毛片在线| 久久大逼视频| 国产亚洲va综合人人澡精品| 亚洲深夜福利| 亚洲精品欧美日韩专区| 久久亚洲午夜电影| 韩国三级电影久久久久久| 亚洲免费人成在线视频观看| 亚洲欧洲在线视频| 欧美成va人片在线观看| 在线观看国产精品淫| 久久久久国产精品一区二区| 亚洲欧美美女| 国产精品亚洲一区| 性视频1819p久久| 亚洲欧美日韩国产一区| 国产精品久久二区二区| 亚洲自拍都市欧美小说| 亚洲精品男同| 欧美日韩一区二区在线| 9l国产精品久久久久麻豆| 亚洲国产精品激情在线观看| 欧美a级片网站| 亚洲另类自拍| 亚洲黄色影院| 欧美粗暴jizz性欧美20| 亚洲精品免费在线观看|