一个简单但不容易想明白的问题!精通c的请进!

yifei429 2004-11-21 02:56:19
假设有四个文件:main.c main.h other.c other.h

main.c 中有#include "main.h"
main.h中有#include "other.h"
other.h中有 int max(int,int);
other.c 中有 int max(int a,int b){return a;}

现在编译 main.c 后生成main.exe不能使用other.c中的max方法,怎么才能让main中可疑使用max方法.
(不能用在other.h中建类,不能把方法体移到other.h中,有什么别的方法么?比如"宏",配置文件之类方法??)

谢谢了!
...全文
114 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
kevin_start 2004-11-21
  • 打赏
  • 举报
回复
两种方法都可以,在other.h中声明 extern int max(int, int)
或是把main.c和other.c一起编译.
anguskwan 2004-11-21
  • 打赏
  • 举报
回复
extern 可以啊~
外部函数
y8t47h 2004-11-21
  • 打赏
  • 举报
回复

你用的是什么编译器?

choujs 2004-11-21
  • 打赏
  • 举报
回复

不知道你的意思是什么?只要把main.c和other.c一起编译就没问题啊。
另外在谈论C时请不要使用类、方法这些术语,这些是C++的名词。上述
max()应称为函数(function)。
dongyuanzhang 2004-11-21
  • 打赏
  • 举报
回复
怎么才能让main中可疑使用max方法.

在main.c中添加声明extern int max(int,int);就行了!
yifei429 2004-11-21
  • 打赏
  • 举报
回复
假设有四个文件:main.c main.h other.c other.h

main.c 中有#include "main.h"
main.h中有#include "other.h"
other.h中有 int max(int,int);
other.c 中有#include "other.h" int max(int a,int b){return a;}

现在编译 main.c 后生成main.exe不能使用other.c中的max方法,怎么才能让main中可疑使用max方法.
(不能用在other.h中建类,不能把方法体移到other.h中,有什么别的方法么?比如"宏",配置文件之类方法??)

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧