extern "C"实现C与C++混合编程(笔记)
2014-02-18 21:57
417 查看
#ifdef __cplusplus extern "C" { #endif ...//代码 #ifdef __cpluscplus }; #endif
extern "C"表示不进行名字改编。C++支持重载,所以编译器会对重载的函数进行名字改编(name managling)。
#include <iostream> using namespace std; void func(int a, int b){ cout<<"int fun"<<endl; } void func(double a, double b) { cout<<"double fun"<<endl; } void func(int a, int b, int c); int main(void) { func(3,4); func(3.3,4.4); func(3,4,5); return 0; }func(3,4,5)这行报错,从控制台可以看到:
error LNK2001: 无法解析的外部符号 "void __cdecl func(int,int,int)" (?func@@YAXHHH@Z)改编后的方法名加入了参数和返回值类型。
相关文章推荐
- extern "C" 的含义:实现C++与C及其他语言的混合编程
- C和C++混合编程中的extern "C" {}
- C++学习笔记(三) 域运算符 new delete运算符 重载 name managling与extern"c" 带默认参数函数
- extern "C" C和C++混合编程问题
- 深入理解C/C++混合编程(关于#ifdef __cplusplus extern "C" {...}的用法)
- C++函数重载实现的原理以及为什么在C++中调用C语言编译的函数时要加上extern "C"声明
- C/C++混合编程——extern "C"
- 深入理解C/C++混合编程(关于#ifdef __cplusplus extern "C" {...}的用法)
- extern "C" c++如何实现函数的重载
- extern和extern“c"作用详解 以及C和C++混合编程 在文章:3.深层揭密extern "C" 部分可以看到
- 第五天2017/04/06(下午1:C、C++混合编程 与 #ifdef __cplusplus extern "C"{ })
- C /C++混合编程——关于“#ifdef __cplusplus” 和 " extern "C" "
- C和C++之用extern "C"实现它们之间的互调
- extern和extern“c"作用详解 以及C和C++混合编程 在文章:3.深层揭密extern "C" 部分可以看到 .
- extern "C" 的含义:实现C++与C及其它语言的混合编程
- extern "C" 实现C++ 与 C的混合编程
- C++ 中实现C函数(同cpp文档)extern"C"
- C/C++混合编程 —— extern "C" 的用法
- 【C/C++】struct探索·extern "C"含义探索 ·C++与C的混合编程·C 语言高效编程的几招
- C和C++接口相互调用 extern "C"