解决C++中multiple definition of问题(二十三)
C++ 解决 of multiple 二十三 definition 问题
2023-09-14 09:09:58 时间
1.代码示例
1.global.h
#ifndef _GLOBAL_H
#define _FACEDETECT_H
struct People{
string name;
int age;
}p_info;
#endif
2.global.cpp实现函数包含global.h头文件
#include "global.h"
3.test.cpp测试函数包含global.h头文件
#include "global.h"
在编译的时候就会出错:
first defined here
multiple definition of ‘pinfo’
原因是因为在多次包含global.h时重复定义了结构体变量pinfo,即使包含了#ifndef也一样报错。
解决方法:
1.在global.cpp实现函数里加入
#include "global.h"
struct People p_info;
2. 在global.h里修改
#ifndef _GLOBAL_H
#define _FACEDETECT_H
struct People{
string name;
int age;
};
extern struct People p_info;
#endif
3.3.test.cpp测试函数无需修改.
#include "global.h"
到此问题解决!!!
相关文章
- C++ stl_stl函数
- C++ 漫谈哈夫曼树
- pip 安装 torch 报错Microsoft Visual C++ Redistributable is not installed
- ❤ 挑战C站最强C++ STL标准库总结(内含大量示例)
- c++ decltype用法_c++ typedef struct
- 菱形继承问题及解决方法—虚继承与虚基类(C++)
- C++字符串加密_c++字符串连接函数
- c++的链表-链表入门(C++)
- 从超过100万个项目中搜索C++代码示例
- 【错误记录】Visual Studio 编译 C++ 代码报错 ( To disable deprecation, use _CRT_SECURE_NO_WARNINGS. )
- C++设计模式--Visitor模式
- C++著名程序库的比较和学习经验详解编程语言
- C++中点操作符和箭头操作符的使用详解
- 解决C++中事件不响应的方法详解
- C++产生随机数的实现代码
- C++指向类成员函数的指针详细解析
- C++中可正确获取UTF-8字符长度的函数分享