short a = 2000; int b; b = a;
class A {};
class B {
public:
B (A a) {}
};
A a;
B b = a;
double x = 10.3; int y; y = int (x); // 函数式写法 y = (int) x; // C风格写法
#include <iostream>
class CDummy {
float i,j;
public:
CDummy () { i=1; j=1; }
};
class CAddition {
int x,y;
public:
CAddition () { x=1; y=1; }
int result() { return x+y;}
};
int main () {
CDummy d;
CAddition * padd;
padd = (CAddition*) &d;
std::cout << padd->result();
return 0;
}
class CBase { };
class CDerived: public CBase { };
CBase b;
CDerived d;
CBase* pb = dynamic_cast<CBase*>(&d); // 子类转父类,正确
//CDerived* pd = dynamic_cast<CDerived*>(&b); // 父类转子类,错误
class CBase {};
class CDerived: public CBase {};
CBase * a = new CBase;
CDerived * b = static_cast<CDerived*>(a);
double d = 3.14159265; int i = static_cast<int>(d); void* p = static_cast<void*>(&i); //任意类型转换成void类型
class A {};
class B {};
A * a = new A;
B * b = reinterpret_cast<B*>(a)
typedef void(*Func)(); // 声明一种函数指针定义,返回void Func pFunc; // 定义FuncPtr类型的数组 //pFunc = &test; // 编译错误!类型不匹配 pFunc = reinterpret_cast<Func>(&test); // 编译成功!转换函数指针类型
#include <iostream>
void print (char * str){
std::cout << str ;
}
int main () {
const char* c = "hello world";
print ( const_cast<char *> (c) );
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有