February 2nd Monday 2009 (二月 二日 月曜日)
来源:互联网 发布:网络软文收费 编辑:程序博客网 时间:2024/04/29 18:13
Today is the first work day in Chinese new year. During the Spring Festival holiday, I reviewed the principle of the compile.
The long holiday is precious for me.
C++ has three components supporting RTTI:
* The dynamic_cast operator generates a pointer to a derived type from a pointer to a base type, if possible. Otherwise, the
operator returns 0, the null pointer.
* The typeid operator returns a value identifying the exact type of an object.
* A type_info structure holds information about a particular type.
You can use RTTI only with a class hierarchy having virtual functions. The reason for this is that these are the only class
hierarchies for which you should be assigning the addresses of derived objects to base class pointers.
RTTI works only for classes with virtual functions.
dynamic_cast<Type *>(pt)
converts the pointer pt to a pointer of type Type * if the pointed-to object (*pt) is of type Type or else derived directly
or indirectly from type Type. Otherwise, the expression evaluates to 0, the null pointer.
The purpose of this operator is to allow upcasts within a class hierarchy (such type casts being safe because of the is-a relationship)
and to disallow other casts.
The typeid Operator and type_info Class
The typeid operator lets you determine if two objects are the same type. Somewhat like sizeof, it accepts two kinds of arguments:
* The name of a class
* An expression that evaluates to an object
The typeid operator returns a reference to a type_info object, where type_info is a class defined in the typeinfo header file
(formerly typeinfo.h). The type_info class overloads the == and != operators so that you can use these operators to compare types.
For example, the expression
typeid(Magnificent) == typeid(*pg)
evaluates to the bool value true if pg points to a Magnificent object and to false otherwise. If pg happens to be a null pointer,
the program will throw a bad_typeid exception. This exception type is derived from the exception class and is declared in the typeinfo
header file.
The implementation of the type_info class will vary among vendors, but it will include a name() member that returns an implementation-dependent
string that typically would be the name of the class.
static_cast < type-name > (expression)
It's valid only if type_name can be converted implicitly to the same type expression has, or vice versa. Otherwise, the cast is an error. Suppose
High is a base class to Low and that Pond is an unrelated class.
const_cast < type-name > (expression)
The result making such a cast is an error if any other aspect of the type is altered. That is, type_name and expression must be of the same type
except they can differ in the presence or absence of const or volatile.
High bar;
const High * pbar;
...
High * pb = const_cast<High *> (pbar); // valid
Low * pl = const_cast<Low *> (pbar); // invalid
- February 2nd Monday 2009 (二月 二日 月曜日)
- 2008 February 2nd Saturday (二月 二日 土曜日)
- February 23th Monday 2009 (二月 二十三日 月曜日)
- 2008 February 25th Monday (二月 二十五日 月曜日)
- 2008 February 4th Monday (二月 四日 月曜日)
- 2008 February 18th Monday (二月 十八日 月曜日)
- 2009 March 2nd Monday (三月 二日 月曜日)
- February 9th Monday 2009 (二月 九日 月曜日)
- February 16th Monday 2009 (二月 十六日 月曜日)
- April 2nd Monday (四月 二日 月曜日)
- February 24th Tuesday 2009 (二月 二十四日 火曜日)
- February 25th Wednesday 2009 (二月 二十五日 水曜日)
- February 2nd Friday (一月 二日 金曜日)
- February 3rd Tuesday 2009 (二月 三日 火曜日)
- February 4th Wednesday 2009 (二月 四日 水曜日)
- February 5th Thursday 2009 (二月 五日 木曜日)
- February 10th Tuesday 2009 (二月 十日 火曜日)
- February 11th Wednesday 2009 (二月 十一日 水曜日)
- symbain发短信
- ARM开发培训
- "The file you are trying to open, '[filename]', is in a different format" Excel Error
- 3.7编程练习
- 多线程内存泄露
- February 2nd Monday 2009 (二月 二日 月曜日)
- Carbide.c++ IDE的常用快捷键和技巧
- Tomcat启动警告:log4j:WARN No appenders could be found for logger (org.apache.commons.digester.Digester.sax).
- Windows Live之Silverlight Streaming学习笔记
- February 3rd Tuesday 2009 (二月 三日 火曜日)
- February 4th Wednesday 2009 (二月 四日 水曜日)
- February 5th Thursday 2009 (二月 五日 木曜日)
- February 6th Friday 2009 (二月 六日 金曜日)
- February 9th Monday 2009 (二月 九日 月曜日)