Syntax ( type-name ) expression
n addition to the implicit conversions, the following conversions are allowed:
1、Any integer can be cast to any pointer type. Except for the null pointer constants such as NULL (which doesn't need a cast), the result is implementation-defined.
任何整型都可以被强制转换成指针类型。除了Null Point.强制转换结果由编译器定义。
2、Any pointer type can be cast to any integer type. The result is implementation-defined, even for null pointer values (they do not necessarily result in the value zero).
任何指针可以被转换成整型。强制转换结果由编译器实现。
3、Any pointer to object can be cast to any other pointer to object. If the value is not correctly aligned for the target type, the behavior is undefined.
任何指针类型对象可以转换成其它任何类型的指针对象。
if the value is converted back to the original type, it compares equal to the original value.
如果,指针又通过强制转换成最初的对象,那边指针还是原来的数据。
If a pointer to object is cast to pointer to any character type, the result points at the lowest byte of the object and may be incremented up to sizeof the target type
若果指针被强制转换成 char类型(char,unsiged char siged char)指针,则char指针指向原来指针开始位置(lowest byte).
in other words, can be used to examine object representation or to make a copy via memcpy or memmove
4、Any pointer to function can be cast to a pointer to any other function type. If the resulting pointer is converted back to the original type, it compares equal to the original value.
任何函数对象的指针可以转换成其它任何函数的指针。转换的结果由编译器实现。
5、When casting between pointers (either object or function), if the original value is a null pointer value of its type, the result is the correct null pointer value for the target type.
n addition to the implicit conversions, the following conversions are allowed:
1、Any integer can be cast to any pointer type. Except for the null pointer constants such as NULL (which doesn't need a cast), the result is implementation-defined.
任何整型都可以被强制转换成指针类型。除了Null Point.强制转换结果由编译器定义。
2、Any pointer type can be cast to any integer type. The result is implementation-defined, even for null pointer values (they do not necessarily result in the value zero).
任何指针可以被转换成整型。强制转换结果由编译器实现。
3、Any pointer to object can be cast to any other pointer to object. If the value is not correctly aligned for the target type, the behavior is undefined.
任何指针类型对象可以转换成其它任何类型的指针对象。
if the value is converted back to the original type, it compares equal to the original value.
如果,指针又通过强制转换成最初的对象,那边指针还是原来的数据。
If a pointer to object is cast to pointer to any character type, the result points at the lowest byte of the object and may be incremented up to sizeof the target type
若果指针被强制转换成 char类型(char,unsiged char siged char)指针,则char指针指向原来指针开始位置(lowest byte).
in other words, can be used to examine object representation or to make a copy via memcpy or memmove
4、Any pointer to function can be cast to a pointer to any other function type. If the resulting pointer is converted back to the original type, it compares equal to the original value.
任何函数对象的指针可以转换成其它任何函数的指针。转换的结果由编译器实现。
5、When casting between pointers (either object or function), if the original value is a null pointer value of its type, the result is the correct null pointer value for the target type.
可以把函数指针和指针之间相互强制转换。
Object* o1 = new Object();
o1->o = 9;
long l1 = (long)o1;
cout << "point ->long:" << l1 << endl;
Object* o2 = (Object*)l1;
cout << "object.o:" << o2->o << endl;