double slope = static_cast<double>(j) / i;
typedef void (* FUNC)();
int DoSomething (int i)
{
cout<<"DoSomething" <<endl;
return 0;
}
void Test ()
{
// reinterpret_cast可以编译器以FUNC的定义方式去看待 DoSomething函数
// 所以非常的BUG,下面转换函数指针的代码是不可移植的,所以不建议这样用
// C++不保证所有的函数指针都被一样的使用,所以这样用有时会产生不确定的结果
FUNC f = reinterpret_cast< FUNC>(DoSomething );
f();
}
#include<iostream>
#include<Windows.h>
#include<assert.h>
using namespace std;
int main()
{
const int a = 2;
int *p = const_cast<int*>(&a);
*p = 3;
cout << a << endl;
system("pause");
return 0;
}
#include<iostream>
#include<Windows.h>
#include<assert.h>
using namespace std;
int main()
{
volatile const int a = 2;
int *p = const_cast<int*>(&a);
*p = 3;
cout << a << endl;
system("pause");
return 0;
}
#include<iostream>
#include<Windows.h>
#include<assert.h>
using namespace std;
class AA
{
public:
virtual void fun1()
{
cout << "hehe" << endl;
}
public:
int a;
};
class BB :public AA
{
public:
virtual void fun1()
{
cout << "heh2e" << endl;
}
public:
int c;
};
int main()
{
AA* q = new AA();
BB* p = new BB();
AA* a;
BB* b;
b = dynamic_cast<BB*>(q);
if (b == NULL)
{
cout << "AA为基类" << endl;
}
else{
cout << "AA为子类" << endl;
}
a = dynamic_cast<AA*>(p);
if (a == NULL)
{
cout << "BB为基类" << endl;
}
else
{
cout << "BB为子类" << endl;
}
system("pause");
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有