首页
IT
登录
6mi
u
盘
搜
搜 索
IT
C++复习3extern "C"
C++复习3extern "C"
xiaoxiao
2021-03-25
103
extern “C”
/*************main.c***************/
#include <iostream>
#include "head.h"
using
namespace
std
;
extern
"C"
{
//里面按照C的规则编译
//此时函数不能重载
void
fun1(
void
){}
void
fun2(
int
a){} }
//C++中可以重载
void
fun(
void
){}
void
fun(
int
a){}
int
main() {
//调用头文件中函数
fun_1(
"hello"
); fun_2(
123
);
cout
<<
"Hello world!"
<< endl;
return
0
; }
/*************head.h***************/
#ifndef HEAD_H_INCLUDED
#define HEAD_H_INCLUDED
#ifdef __cplusplus
//C++编译器自动定义这个宏
extern
"C"
{
#endif
// __cplusplus
#include <stdio.h>
void
fun_1(
const
char
*str){
printf
(
"输入的字符串:%s\n"
,str); }
void
fun_2(
int
a){
printf
(
"输入的数字:%d\n"
,a); }
#ifdef __cplusplus
}
#endif
// __cplusplus
#endif
// HEAD_H_INCLUDED
转载请注明原文地址: https://ju.6miu.com/read-22923.html
技术
最新回复
(
0
)