.


:




:

































 

 

 

 





(RTTI) , , . RTTI typeid type_info. Typeinfo typeinfo.

typeid:

typeid ()

typeid ()

type_info, . , bad_typeid.

, (.. type_info , ).

, , type_info , , .

typeid , .

type_info typeinfo.h :

class type_info{

public:

virtual ~ type_info();

bool operator == (const type_info& rhs) const;

bool operator!= (const type_info& rhs) const;

bool before (const type_info& rhs) const;

const char* name () const;

private:

type_info (const type_info& rhs);

type_info& operator = (const type_info& rhs);

};

name , , type_info.

type_info .

private, .

== ! = , before . :

typeid(Tl).before(typeid(T2))

1 2, .

, , , .

:

#include <typeinfo.h>

class {...

public: virtual ~(){...};

};

class : public {...

public: virtual void some_method(){... };

};

void demo (B* ){

if (typeid(*p) == typeid(C))

dynamic_cast<C*>(p)->some_method();

}

int main(){

C* = new C;

demo(c);

return 0;

}

:

void print_type (some_obj *){

cout << type_id(*p).name();

}

typeid , .

 


 

:

1. .. /++. . .: , 2006. 464 .:.

2. .. ++ . 4- . .: , 2005. 890 .: .

3. .., .. : .. 2- . . .: , 2005. 600 .: .

4. .., .. /++. : . .: , 2007. 265 .: .

5. .., .. ++. - : . .: , 2007. 239 .: .

 

:

1. .. ++ Builder 6. 7- . .: , 2010. 1152 ., .

2. . ++. .: , 2011. 371 .: .

3. ., ., . .: . . .: , 2010. 400 .: .

4. . ++. / //. . . .: , 2002. 688 .: .

5. .. ++. . .: -, 2006. 384 .: .

6. .. /++ . .: -, 2006. 288 .: .

 

:

C++Builder.

 

-:

http://citforum.ru - Borland C++

 





:


: 2016-11-12; !; : 745 |


:

:

.
==> ...

1507 - | 1342 -


© 2015-2024 lektsii.org - -

: 0.01 .