编写一个头文件Proc.h

#include <iostream>
using namespace std;
void Proc()
{
cout<<"Hello World!"<<endl;
}

在编写两个头文件add.h

#ifndef __PROC_H
#define __PROC_H
#include "Proc.h"
#endif

int add(int a,int b){
return a+b;
}

sub.h

#ifndef __PROC_H
#define __PROC_H
#include "Proc.h"
#endif

int sub(int a,int b){
return a-b;
}

在主方法中这么写才能保证头文件不被重复引入

#include "stdafx.h"
#ifndef __PROC_H
#define __PROC_H
#include "Proc.h"
#endif
#include "add.h"
#include "sub.h"



int main(int argc, char* argv[])
{
Proc();
return 0;
}

输出:

Hello World!