当前位置:网站首页>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;
}
边栏推荐
- Redis introduction complete tutorial: client communication protocol
- A complete tutorial for getting started with redis: getting to know redis for the first time
- How can enterprises cross the digital divide? In cloud native 2.0
- debug和release的区别
- 实战模拟│JWT 登录认证
- Async await used in map
- ETCD数据库源码分析——处理Entry记录简要流程
- [OpenGL] note 29 anti aliasing (MSAA)
- A complete tutorial for getting started with redis: Pipeline
- Gnawing down the big bone - sorting (II)
猜你喜欢
D3.js+Three. JS data visualization 3D Earth JS special effect
Tweenmax emoticon button JS special effect
小程序vant tab组件解决文字过多显示不全的问题
Set up a website with a sense of ceremony, and post it to 1/2 of the public network through the intranet
位运算符讲解
Redis入门完整教程:哈希说明
heatmap. JS picture hotspot heat map plug-in
[sword finger offer] questions 1-5
【室友用一局王者荣耀的时间学会了用BI报表数据处理】
为什么信息图会帮助你的SEO
随机推荐
Tweenmax emoticon button JS special effect
Complete tutorial for getting started with redis: bitmaps
小程序vant tab组件解决文字过多显示不全的问题
Insert sort, select sort, bubble sort
数据库基础知识
[Jianzhi offer] 6-10 questions
推荐收藏:跨云数据仓库(data warehouse)环境搭建,这货特别干!
A complete tutorial for getting started with redis: transactions and Lua
Persistence mechanism of redis
为什么信息图会帮助你的SEO
[odx Studio Edit pdx] - 0.2 - Comment comparer deux fichiers pdx / odx
【剑指offer】1-5题
Redis入门完整教程:Redis Shell
Analysis of environmental encryption technology
字体设计符号组合多功能微信小程序源码
[sword finger offer] questions 1-5
[graph theory] topological sorting
Is Huatai Securities a nationally recognized securities firm? Is it safe to open an account?
机器学习在房屋价格预测上的应用
A complete tutorial for getting started with redis: understanding and using APIs