dynamic_cast
dynamic_cast can be used only with pointers and references to objects. Its purpose is to ensure that the result of the type conversion is a valid complete object of the requested class. Therefore, dynamic_cast is always successful when we cast a class to one of its base classes:
static_cast
static_cast can perform conversions between pointers to related classes, not only from the derived class to its base, but also from a base class to its derived. This ensures that at least the classes are compatible if the proper object is converted, but no safety check is performed during runtime to check if the object being converted is in fact a full object of the destination type. Therefore, it is up to the programmer to ensure that the conversion is safe. On the other side, the overhead of the type-safety checks of dynamic_cast is avoided.
reinterpret_cast
reinterpret_cast converts any pointer type to any other pointer type, even of unrelated classes. The operation result is a simple binary copy of the value from one pointer to the other. All pointer conversions are allowed: neither the content pointed nor the pointer type itself is checked. It can also cast pointers to or from integer types. The format in which this integer value represents a pointer is platform-specific. The only guarantee is that a pointer
const_cast
This type of casting manipulates the constness of an object, either to be set or to be removed. For example, in order to pass a const argument to a function that expects a non-constant parameter:
typeid
typeid allows to check the type of an expression:
typeid (expression)
This operator returns a reference to a constant object of type type_info that is defined in the standard header file <typeinfo>. This returned value can be compared with another one using operators == and != or can serve to
obtain a null-terminated character sequence representing the data type or class name by using its name() member.
分享到:
相关推荐
千锋C++笔记.zip
C++笔记.rarC++笔记.rarC++笔记.rarC++笔记.rarC++笔记.rarC++笔记.rarC++笔记.rarC++笔记.rar
C++学习笔记C++学习笔记C++学习笔记C++学习笔记C++学习笔记
c++学习笔记/知识要点精华版
QT 4 c++ 笔记 QT 4 c++ 笔记 QT 4 c++ 笔记 QT 4 c++ 笔记 QT 4 c++ 笔记 QT 4 c++ 笔记
C++笔记.md
自己整理的c++笔记,初学者可以参考,必有益处
c++完美学习笔记c++完美学习笔记c++完美学习笔记c++完美学习笔记
作者全部手打创作的自考C++笔记,含课本中例子的详细分析,(上)共47200字,就是没有学过C语言的人认真看了以后,也可学会并通过C++自考
c++笔记.txt 本人所写,内容丰富,全面。包含c++的各个知识点。供广大网友学习!
C++学习笔记
c++学习笔记.pdf
某课网C++远征的课程截图整理的笔记,该课程适合入门,
我自己的笔记,根据C++知识点来概括,里面有例子,详解,也有一些重点算法(10个),关键是类,结构,函数的笔记,唉。。自己记录的,写得很鸟的,只适合鸟鸟们看,高手千万不要下,不然笑话我啊。但写得辛苦,10分...
C++ 学习笔记C++ 学习笔记C++ 学习笔记C++ 学习笔记
C++笔记精华,非常不错的,初学者的学习c++的笔记。大学中的
大一下c++笔记.md
二级C++笔记.docx
基础C/C++课程,包含UC、C++笔记,适合初学者使用。含有文本文档。
C++笔记(1).md