在1.cpp中写上出被调函数的定义
#include<iostream>
using namespace std;
int fuc();
{
return 0;
}
在头文件(Headers)中声明fuc()函数,hello.h
int fuc();
在2.cpp调用函数,并包含头文件
#include<iostream>
#include"hello.h"
using namespace std;
int main()
{
int a=fuc();
cout<<a<<endl;
}
输出: 0
本文介绍了一个简单的C++程序实例,演示了如何在一个源文件中定义并实现函数,然后在另一个源文件中通过包含头文件来调用该函数。此过程涉及函数的声明、定义和调用的基本步骤。
3675

被折叠的 条评论
为什么被折叠?



