static_cast Operator The expression static_cast < type-id > ( expression ) converts expression to the type of type-id based solely on the types present in the expression. No run-time type check is made to ensure
A standard cast conversion between built-in types: C++ // expre_CastOperator.cpp// compile with: /EHsc// Demonstrate cast operator#include<iostream>usingnamespacestd;intmain(){doublex =3.1;inti;cout<<"x = "<< x <<endl; i = (int)x;// assign i the integer part of xcout<<"i = ...
cast operator Performs explicit type conversion Syntax (type-name)expression where type-name-either the typevoidor anyscalar type expression-anyexpressionofscalar type(unlesstype-nameisvoid, in which case it can be anything) Explanation Iftype-nameisvoid, thenexpressionis evaluated for its side-...
// static_cast_Operator.cpp// compile with: /LDclassB{};classD:publicB {};voidf(B* pb, D* pd){ D* pd2 =static_cast<D*>(pb);// Not safe, D can have fields// and methods that are not in B.B* pb2 =static_cast<B*>(pd);// Safe conversion, D always// contains all of...
A standard cast conversion between built-in types: C++ // expre_CastOperator.cpp// compile with: /EHsc// Demonstrate cast operator#include<iostream>usingnamespacestd;intmain(){doublex =3.1;inti;cout<<"x = "<< x <<endl; i = (int)x;// assign i the integer part of xcout<<"i = ...
// dynamic_cast_8.cpp// compile with: /GR /EHsc#include<stdio.h>#include<iostream>structA{virtualvoidtest(){ printf_s("in A\n"); } };structB:A {virtualvoidtest(){ printf_s("in B\n"); }voidtest2(){ printf_s("test2 in B\n"); } };structC:B {virtualvoidtest(){ printf...
原文链接:http://www.cnblogs.com/ider/archive/2011/07/30/cpp_cast_operator_part3.html reinterpret_cast <new_type> (expression) reinterpret_cast运算符是用来处理无关类型之间的转换;它会产生一个新的值,这个值会有与原始参数(expressoin)有完全相同的比特位。
cast operator From cppreference.com <c |language Performs explicit type conversion Syntax (type-name)expression where type-name-either the typevoidor anyscalar type expression-anyexpressionofscalar type(unlesstype-nameis void, in which case it can be anything)...
reinterpret_cast operator Run-Time Type Information (RTTI) Statements Namespaces Enumerations Unions Functions Operator overloading Classes and structs Lambda expressions in C++ Arrays References Pointers Exception handling in C++ Assertion and user-supplied messages ...
// static_cast_Operator.cpp// compile with: /LDclassB{};classD:publicB {};voidf(B* pb, D* pd){ D* pd2 =static_cast<D*>(pb);// Not safe, D can have fields// and methods that are not in B.B* pb2 =static_cast<B*>(pd);// Safe conversion, D always// contains all of...