_cast<A*>(this), this){}};structBase{virtual~Base(){}};structDerived:Base{virtualvoidname(){}};intmain(){D d;// 最终派生对象A&a=d;// 向上转换,可以用 dynamic_cast,但不是必须的[[maybe_unused]]D&new_d=dynamic_cast<D&>(a);// 向下转换[[maybe_unused]]B&new_b=dynamic_cast<...
dynamic_cast在继承层级中转换 const_cast添加或移除cv限定符 reinterpret_cast转换类型到无关类型 C 风格转换以static_cast、const_cast及reinterpret_cast的混合转换一个类型到另一类型 new创建有动态存储期的对象 delete销毁先前由 new 表达式创建的对象,并释放其所拥有的内存区域 ...
5.2.10 Reinterpret cast [expr.reinterpret.cast] See also const_castconversionadds or removes const static_castconversionperforms basic conversions dynamic_castconversionperforms checked polymorphic conversions explicit castspermissive conversions between types ...
static_cast converts one type to another related type dynamic_cast converts within inheritance hierarchies const_cast adds or removes cv-qualifiers reinterpret_cast converts type to unrelated type C-style cast converts one type to another by a mix of static_cast, const_cast, and reinterpret_cas...
if( x < 0 ) break; cout << x << endl; x++; } break语句只能跳出本层循环,假如你要跳出一个三重嵌套的循环,你就要使用包含其它的逻辑或者用一个goto语句跳出这个嵌套循环. case 在switch里面用来检测匹配 . default,switch catch catch 语句通常通过throw语句捕获一个异常. ...
6) 强转为“对象的右值引用”表达式,比如,static_cast<char&&>(x)。 x值表达式的属性[properties]: 1) 拥有右值[rvalue]表达式的所有属性。 2) 拥有左值[glvalue]表达式的所有属性。 [注] 类似于纯右值,x值绑定右值引用,但不同的是,x值可能是多态的[polymorphic],并且非类[non-class]的x值可能被const或...
std::bad_cast This can be thrown by dynamic_cast. std::bad_exception This is useful device to handle unexpected exceptions in a C++ program. std::bad_typeid This can be thrown by typeid. std::logic_error An exception that theoretically can be detected by reading the code. std::domain_...
a cast expression to non-reference type, such as static_cast(x), std::string{}, or (int)42; the this pointer; (this指针也是纯右值,因为this也是一个地址) a lambda expression, such as [](int x){ return x * x; }.(since C++11) ...
const_cast, static_cast, dynamic_cast, reinterpret_cast und typeid sind nicht enthalten, da sie immer eindeutig sind. Einige der Operatoren haben alternative Schreibweisen (z.B. and für &&, or für ||, not für !, usw.). Siehe auch Auswertungsreihenfolge von Operator-Argumenten zur...
dynamic_cast else enum explicit export extern false float for friend goto if inline int long mutable namespace new noexcept not not_eq nullptr operator or or_eq private protected public reflexpr register reinterpret_cast requires return short signed sizeof static static_assert static_cast struct swi...