当前位置:网站首页>Debug:与泛型有关的“无法解析的外部符号”
Debug:与泛型有关的“无法解析的外部符号”
2022-07-27 07:01:00 【本菜;】
我们在temp.h中声明函数在temp.cpp中实现函数,这是没问题的,但仅仅限制与普通函数,在函数模板上,这种行为是不可取的;
为什么报错
这要说到编译和链接的过程了,首先编译temp.h文件,编译器会解读函数声明,然后编译器会留下一个标记符号,当编译到实现文件时,会将其函数地址链接起来,但是我们知道,函数模板在编译的时候是不会进行实例化的,所以就找不到地址。
当然,我们没有实例化该函数的时候是不会报错的,因为这仅仅相当于我们写了一个只有函数声明,而没有实现的函数,但当我们隐式实例化该函数模板时,就会报错,因为函数地址压根不存在;
怎么解决
很简单,我们只要把函数的声明和实现放到一起实现就可以了,这样编译器编译到实现文件的时候就不会去寻址了;
当然我们要限定函数的作用范围,要在前面加一个static修饰符
边栏推荐
- Chapter 6 Shell Logic and Arithmetic
- Closed hash and open hash resolve hash conflicts
- (2022 Niuke multi school III) j-journey (Dijkstra)
- 临界区(critical section 每个线程中访问 临界资源 的那段代码)和互斥锁(mutex)的区别(进程间互斥量、共享内存、虚拟地址)
- 用户解锁SM04 SM12
- Chapter 6 Shell Logic and Arithmetic
- Error when connecting to MySQL: public key retrieval is not allowed [solution]
- Use the PIP command to switch between different mirror sources
- Simple rotation chart
- ClickHouse 笔记1 | 简介、特点 | 基于CentOS7系统的安装与使用 | 常用数据类型 | MergeTree 表引擎 | SQL操作
猜你喜欢

Tcp/ip protocol analysis (tcp/ip three handshakes & four waves + OSI & TCP / IP model)

Understanding and learning of properties class and properties configuration file

Bash: create a function that returns a Boolean value

Temperature and humidity measurement and display device based on Arduino

Using loops to process data in tables in kettle

2022 0726 Gu Yujia's study notes

Grayog log server single node deployment
![Error when connecting to MySQL: public key retrieval is not allowed [solution]](/img/b3/41523d44924ec203e40453bace6627.png)
Error when connecting to MySQL: public key retrieval is not allowed [solution]

flink1.14 sql基础语法(一) flink sql表查询详解

Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community
随机推荐
闭散列和开散列解决哈希冲突
Using soci to connect Oracle with PostgreSQL and SQLite on rhel8
flink去重(一)flink、flink-sql中常见的去重方案总结
IDEA中文乱码怎么办
基于Arduino的温度、湿度测量显示装置
The DrawImage method calls the solution of not displaying pictures for the first time
Regular expression foundation sorting
Docker install MySQL 8.0.28
Use of tigervnc
记录一个自己挖的坑~
Pg_ relation_ Size question
面试复盘五
Will Flink CDC constantly occupy Oracle's memory by extracting Oracle's data, and finally cause oracle-040
用户解锁SM04 SM12
(2022牛客多校三)J-Journey(dijkstra)
2022 0726 Gu Yujia's study notes
UiAutomator常用类之UI手势动作
[wsl2] configure the USB camera connecting the USB device and using the host
(2022 Hangdian multi school III) 1009.package delivery (greedy)
Routing between VLANs (explanation + verification)