c++静态类型转换.doc

c静态类型转换

//该模块中的函数可能会被C程序调用,也可能被C++程序调用 #include iostream #include a.h using namespace std; void show(void) { cout 无论是什么程序调用我都没有问题,这就叫做任性! endl; } a.h #ifndef _A_H #define _A_H //该模块中的函数可能会被C程序调用,也可能被C++程序调用 #ifdef __cplusplus extern C { #endif void show(void); #ifdef __cplusplus } #endif #endif //_SHOW_H main.cpp //使用C++程序调用C++模块中的函数 #include a.h int main(void) { show(); return 0; } main.c //使用C程序调用C++模块中的函数 #include a.h int main(void) { show(); return 0; } 静态类型转换 目标类型 变量名=static_cast目标类型(源类型变量名) 功能:当目标类型和源类型之间只要有一个方向可以发生隐式类型转换,则在两个方向上都可以进行静态类型转换, 否则不能进行类型转换 常量类型转换 目标类型 变量名

文档评论(0)

1亿VIP精品文档

相关文档