当前位置:网站首页>Header file duplicate definition problem solving "c1014 error“
Header file duplicate definition problem solving "c1014 error“
2022-07-04 23:07:00 【Programming segment】
For example, now there are three files , Two header files , One .cpp file
header1.h
#include "header2.h"
int fun2();
header2.h
#include "header1.h"
int fun();
main.cpp
#include "header1.h"
int main()
{
return 0;
}
The compiler will replace the header file in the preprocessing process , Finally, the following code is formed , The header file 1 Include header file 2, The header file 2 Also includes header file 1, Nesting with each other , This is the compiler will report an error “C1014 Contains too many files : depth = 1024 ”
#include "header1.h"
...
int fun();
int fun2();
int main()
{
return 0;
}
There are two solutions :
- One is
#ifndef
solve
But this name is customized , There may be the same time , For example, two files are written at the same timeHEADER_1
, This will reduce the number of header files , Therefore, it is suggested to adopt the second
header1.h
#ifndef HEADER_1
#define HEADER_1
#include "header2.h"
int fun2();
#endif
header2.h
#ifndef HEADER_2
#define HEADER_2
#include "header1.h"
int fun();
#endif
main.cpp
#include "header1.h"
int main()
{
return 0;
}
After the header file is expanded
#define HEADER_1
#define HEADER_2
#ifndef HEADER_1
#define HEADER_1
#include "header2.h"
int fun2();
#endif
int fun();
int fun2();
int main()
{
return 0;
}
- The other is to adopt
#pragma once
The principle of this implementation is , There will be a count inside , Indicates that this header file will only be expanded once
header1.h
#pragma once
#include "header2.h"
int fun2();
header2.h
#pragma once
#include "header1.h"
int fun();
main.cpp
#include "header1.h"
int main()
{
return 0;
}
边栏推荐
- Analog rocker controlled steering gear
- Redis getting started complete tutorial: publish and subscribe
- [Lua] Int64 support
- MP进阶操作: 时间操作, sql,querywapper,lambdaQueryWapper(条件构造器)快速筛选 枚举类
- Google Earth engine (GEE) - tasks upgrade enables run all to download all images in task types with one click
- Advanced area of attack and defense world misc 3-11
- PICT 生成正交测试用例教程
- String类中的常用方法
- Summary of wechat applet display style knowledge points
- 【机器学习】手写数字识别
猜你喜欢
[OpenGL] note 29 anti aliasing (MSAA)
The new version judges the code of PC and mobile terminal, the mobile terminal jumps to the mobile terminal, and the PC jumps to the latest valid code of PC terminal
Redis入门完整教程:HyperLogLog
小程序vant tab组件解决文字过多显示不全的问题
Redis入门完整教程:Bitmaps
Attack and defense world misc advanced zone 2017_ Dating_ in_ Singapore
Persistence mechanism of redis
Advanced area a of attack and defense world misc Masters_ good_ idea
One of the commonly used technical indicators, reading boll Bollinger line indicators
S32 Design Studio for ARM 2.2 快速入门
随机推荐
Sword finger offer 67 Convert a string to an integer
Redis入门完整教程:GEO
Persistence mechanism of redis
企业如何跨越数字化鸿沟?尽在云原生2.0
微信公众号解决从自定义菜单进入的缓存问题
Wechat official account solves the cache problem of entering from the customized menu
C语言快速解决反转链表
Redis入门完整教程:键管理
Redis getting started complete tutorial: publish and subscribe
MP进阶操作: 时间操作, sql,querywapper,lambdaQueryWapper(条件构造器)快速筛选 枚举类
Redis入门完整教程:Bitmaps
Redis入门完整教程:Redis使用场景
Tweenmax emoticon button JS special effect
The new version judges the code of PC and mobile terminal, the mobile terminal jumps to the mobile terminal, and the PC jumps to the latest valid code of PC terminal
Redis入门完整教程:API的理解和使用
Redis getting started complete tutorial: Geo
MySQL数据库备份与恢复--mysqldump命令
Redis introduction complete tutorial: detailed explanation of ordered collection
Analysis of environmental encryption technology
Sword finger offer 68 - ii The nearest common ancestor of binary tree