当前位置:网站首页>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;
}
边栏推荐
- 头文件重复定义问题解决“C1014错误“
- Redis getting started complete tutorial: hash description
- 剑指 Offer 65. 不用加减乘除做加法
- Object detection based on OpenCV haarcascades
- Notepad++--编辑的技巧
- 位运算符讲解
- A complete tutorial for getting started with redis: hyperloglog
- Redis入门完整教程:哈希说明
- [odx Studio Edit pdx] - 0.2 - Comment comparer deux fichiers pdx / odx
- Redis入门完整教程:Redis Shell
猜你喜欢
随机推荐
常用技术指标之一文读懂BOLL布林线指标
LabVIEW中比较两个VI
MP进阶操作: 时间操作, sql,querywapper,lambdaQueryWapper(条件构造器)快速筛选 枚举类
[roommate learned to use Bi report data processing in the time of King glory in one game]
[ODX studio edit PDX] - 0.2-how to compare two pdx/odx files of compare
Notepad++ -- editing skills
PICT 生成正交测试用例教程
【ODX Studio编辑PDX】-0.2-如何对比Compare两个PDX/ODX文件
机器学习在房屋价格预测上的应用
剑指 Offer 67. 把字符串转换成整数
Talk about Middleware
Sword finger offer 68 - I. nearest common ancestor of binary search tree
Docker镜像的缓存特性和Dockerfile
Basic knowledge of database
Attack and defense world misc master advanced zone 001 normal_ png
位运算符讲解
智力考验看成语猜古诗句微信小程序源码
Redis入门完整教程:键管理
Redis getting started complete tutorial: Key Management
String类中的常用方法