C++基础学习笔记----第四课(函数的重载、C和C++的相互调用)(二)

2014-11-24 02:51:50 · 作者: · 浏览: 3
plus extern "C" { #endif int func(int a, int b) { return a + b; } int func(const char* s) { return strlen(s); } #ifdef __cplusplus } #endif int main(int argc, char *argv[]) { printf("Press enter to continue ..."); getchar(); return 0; } 注意:在extern “C”的两个大括号之间可以放函数的定义或者函数的声明,不单单是函数的定义。
5. C++编译器不能以C语言的方式编译多个重载函数

错误代码示例:

#ifdef __cplusplus
extern "C"{
#endif

void f()
{
	
}

void f(int i)
{

}
#ifdef __cplusplus
}
#endif

int main()
{
	return 0;
}