当前位置:网站首页>Use unique_ PTR forward declaration? [repetition] - forward declaration with unique_ ptr? [duplicate]
Use unique_ PTR forward declaration? [repetition] - forward declaration with unique_ ptr? [duplicate]
2022-07-03 19:22:00 【Superior virtue and weak water】
problem :
This question already has an answer here: This question has been answered here :
I have found it useful to use forward declaration of classes in combination with std::unique_ptr as in the code below. I found it in std::unique_ptr Using forward declarations of classes is useful , This is shown in the following code .It compiles and works with GCC, but the whole thing seem kind of strange, and I wonder if this is standard behaviour (ie required by the standard)? It compiles and works with GCC Working together , But the whole thing seems a little strange , I want to know if this is standard behavior ( I.e. standard requirements )?Since B isn't a complete type when I declare the unique_ptr . Because when I declare unique_ptr when B Not a complete type .
A.hppA.hpp
#include <memory>class B;class A { std::unique_ptr<B> myptr; // B::~B() can't be seen from herepublic: ~A();};A.cppA.cpp
#include "B.hpp"//B.hpp has to be included, otherwise it doesn't work.A::~A() = default; // without this line, it won't compile // however, any destructor definiton will do.I suspect this has to do with the destructor (and therefore the need to call the destructor of unique_ptr<B> ) is defined in a specific compilation unit (A.cpp). I suspect this has something to do with destructors ( So you need to call unique_ptr<B> Destructor of ) Is in a specific compilation unit (A.cpp) As defined in .
Solution :
Reference resources : https://stackoom.com/en/question/uHlM边栏推荐
- Floating source code comment (38) parallel job processor
- Basic principle of LSM tree
- 第一章:拓广同码小数和s(d, n)
- Analyse du Code du planificateur ego bspline Section Optimizer (1)
- UE source code analysis: uccharactermovementcomponent - rootmotion
- Flutter network and data storage framework construction-b1
- Driveseg: dynamic driving scene segmentation data set
- Nous avons fait une plateforme intelligente de règlement de détail
- 达梦数据库的物理备份和还原简解
- Simple solution of physical backup and restore of Damon database
猜你喜欢

Flutter网络和数据存储框架搭建 -b1

Octopus online ecological chain tour Atocha protocol received near grant worth $50000

Counting from the East and counting from the West will stimulate 100 billion industries. Only storage manufacturers who dare to bite the "hard bone" will have more opportunities

Chapitre 1: le roi de shehan a mal calculé

Merge K ascending linked lists
![第二章:基于分解的求水仙花数,基于组合的求水仙花数, 兰德尔数,求[x,y]内的守形数,探求n位守形数,递推探索n位逐位整除数](/img/c5/0081689817700770f6210d50ec4e1f.png)
第二章:基于分解的求水仙花数,基于组合的求水仙花数, 兰德尔数,求[x,y]内的守形数,探求n位守形数,递推探索n位逐位整除数

【光学】基于matlab涡旋光产生【含Matlab源码 1927期】

Driveseg: dynamic driving scene segmentation data set
![[academic related] how to find the innovation of top papers? Chinese universities won the CVPR Best Student Thesis Award for the first time](/img/06/5a37e2dca9711f8322b657581c3d75.png)
[academic related] how to find the innovation of top papers? Chinese universities won the CVPR Best Student Thesis Award for the first time

Dart JSON编码器和解码器剖析
随机推荐
【光学】基于matlab介电常数计算【含Matlab源码 1926期】
Zhang Fei hardware 90 day learning notes - personal record of day 3, please see my personal profile / homepage for the complete
Ego planner code parsing Bspline_ Optimizer section (2)
记录在模拟器中运行flutter时报的错
Chapter 2: 4-digit Kaplan number, search even digit Kaplan number, search n-digit 2-segment sum square number, m-digit ingenious square number without 0, specify the number to form a 7-digit square nu
SSM integration - joint debugging of front and rear protocols (list function, add function, add function status processing, modify function, delete function)
Simulation scheduling problem of SystemVerilog (1)
Flutter network and data storage framework construction-b1
【水质预测】基于matlab模糊神经网络水质预测【含Matlab源码 1923期】
第一章:递归求n的阶乘n!
第一章:求n的阶乘n!
Record: MySQL changes the time zone
Failed to start component [StandardEngine[Catalina]. StandardHost[localhost]. StandardContext
P1891 crazy LCM (Euler function)
Thinking about festivals
QT -- qfile file read / write operation
[academic related] how to find the innovation of top papers? Chinese universities won the CVPR Best Student Thesis Award for the first time
Scrapy爬虫框架
Nous avons fait une plateforme intelligente de règlement de détail
[free sharing] kotalog diary2022 plan electronic manual ledger