mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-02-04 11:03:58 +08:00
update
This commit is contained in:
35
basic_content/virtual/set4/warn_rtti.cpp
Normal file
35
basic_content/virtual/set4/warn_rtti.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// 在使用时需要注意:被转换对象obj的类型T1必须是多态类型,即T1必须公有继承自其它类,或者T1拥有虚函数(继承或自定义)。若T1为非多态类型,使用dynamic_cast会报编译错误。
|
||||
|
||||
// A为非多态类型
|
||||
|
||||
class A{
|
||||
|
||||
};
|
||||
|
||||
//B为多态类型
|
||||
|
||||
class B{
|
||||
|
||||
public: virtual ~B(){}
|
||||
|
||||
};
|
||||
|
||||
//D为多态类型
|
||||
|
||||
class D: public A{
|
||||
|
||||
};
|
||||
|
||||
//E为非多态类型
|
||||
|
||||
class E : private A{
|
||||
|
||||
};
|
||||
|
||||
//F为多态类型
|
||||
|
||||
class F : private B{
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user