用vc++6.0多文件编程,为什么老是显示错误?

「已注销」
博客专家认证
2013-09-16 09:45:25
这几天才遇到多文件编程的概念,但是一直都弄个不好。真的无奈的很!
在网上搜到的程序,但是就是在我的机子运行不通过!
//main_1.cpp
#include <stdio.h>
#include "functions.h"
#include "myfile.cpp"

int main ()
{
fun1();
fun2();
fun3();
printf ("%d\n", a);
printf ("%d\n", b);
a++;
b++;
printf ("%d\n", a);
printf ("%d\n", b);


return 0;
}

//myfile.cpp
#include <stdio.h>

void fun1()
{
printf ("函数1\n");
return;
}
void fun2 ()
{
printf ("函数2\n");
return;
}
void fun3 ()
{
printf ("函数3\n");
return;
}



//functions.h
void fun1(void);
void fun2(void);
void fun3(void);
int a = 3;
int b = 4;

...全文
522 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
max_min_ 2013-09-17
  • 打赏
  • 举报
回复
引用 3 楼 zhang5476499 的回复:
[quote=引用 1 楼 max_min_ 的回复:] 包含头文件就好,源文件不需要了
那如果我在main函数中定义了fun4函数,而在myfile。cppz中想调用这个函数怎么做啊?如已经在函数中如下声明和定义:
void fun4(void)
{
	printf ("main函数中函数4\n");
	return;
}
//myfile.cpp
#include <stdio.h>

void fun1()
{
	printf ("函数1\n");
	return;
}
void fun2 ()
{
	printf ("函数2\n");
	return;
}
void fun3 ()
{
	printf ("函数3\n");
	return;
}

fun4();
[/quote] 在 function.h中加入fun4的函数申明
「已注销」 2013-09-17
  • 打赏
  • 举报
回复
引用 5 楼 xiongyanbing123123 的回复:
main.cpp中不要写#include "myfile.cpp" include的都是头文件。
要想在myfile1.cpp中调用main_1.cpp函数怎么做啊?
寻找IT之路 2013-09-17
  • 打赏
  • 举报
回复
main.cpp中不要写#include "myfile.cpp" include的都是头文件。
「已注销」 2013-09-17
  • 打赏
  • 举报
回复
怎么在这个myfile1.cpp中输出fun4();中要输出的内容!
「已注销」 2013-09-17
  • 打赏
  • 举报
回复
引用 1 楼 max_min_ 的回复:
包含头文件就好,源文件不需要了
那如果我在main函数中定义了fun4函数,而在myfile。cppz中想调用这个函数怎么做啊?如已经在函数中如下声明和定义:
void fun4(void)
{
	printf ("main函数中函数4\n");
	return;
}
//myfile.cpp
#include <stdio.h>

void fun1()
{
	printf ("函数1\n");
	return;
}
void fun2 ()
{
	printf ("函数2\n");
	return;
}
void fun3 ()
{
	printf ("函数3\n");
	return;
}

fun4();
liwq_jn 2013-09-16
  • 打赏
  • 举报
回复
main.cpp中不要写#include "myfile.cpp" include的都是头文件。
max_min_ 2013-09-16
  • 打赏
  • 举报
回复
包含头文件就好,源文件不需要了

69,373

社区成员

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

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