当前位置:网站首页>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边栏推荐
- P1891 crazy LCM (Euler function)
- Record the errors reported when running fluent in the simulator
- Sentinel source code analysis part II - sentinel dashboard console startup and configuration
- 03 -- QT OpenGL EBO draw triangle
- Succession of flutter
- If the warehouse management communication is not in place, what problems will occur?
- 【水质预测】基于matlab模糊神经网络水质预测【含Matlab源码 1923期】
- 我眼中真正优秀的CTO长啥样
- Driveseg: dynamic driving scene segmentation data set
- High concurrency Architecture - separate databases and tables
猜你喜欢
Why should the gradient be manually cleared before back propagation in pytorch?
DriveSeg:动态驾驶场景分割数据集
Valentine's Day - make an exclusive digital collection for your lover
Summary of composition materials for 2020 high-frequency examination center of educational resources
[optics] vortex generation based on MATLAB [including Matlab source code 1927]
Day_ 18 IO stream system
Php based campus lost and found platform (automatic matching push)
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
【光学】基于matlab涡旋光产生【含Matlab源码 1927期】
[proteus simulation] a simple encrypted electronic password lock designed with 24C04 and 1602LCD
随机推荐
第一章: 舍罕王失算
Analyse du Code du planificateur ego bspline Section Optimizer (1)
我們做了一個智能零售結算平臺
The earliest record
Random numbers in a long range, is that right- Random number in long range, is this the way?
【光学】基于matlab涡旋光产生【含Matlab源码 1927期】
Common text labels
UE source code analysis: uccharactermovementcomponent - rootmotion
Flask generates swagger documents
P3402 persistent and searchable
【疾病识别】基于matlab GUI机器视觉肺癌检测系统【含Matlab源码 1922期】
【光学】基于matlab介电常数计算【含Matlab源码 1926期】
Ego planner code parsing Bspline_ Optimizer section (2)
If the warehouse management communication is not in place, what problems will occur?
Failed to start component [StandardEngine[Catalina]. StandardHost[localhost]. StandardContext
__ Weak and__ The difference between blocks
第二章:4位卡普雷卡数,搜索偶数位卡普雷卡数,搜索n位2段和平方数,m位不含0的巧妙平方数,指定数字组成没有重复数字的7位平方数,求指定区间内的勾股数组,求指定区间内的倒立勾股数组
第一章:递归求n的阶乘n!
[academic related] how to find the innovation of top papers? Chinese universities won the CVPR Best Student Thesis Award for the first time
How does if ($variable) work? [repeat] - how exactly does if ($variable) work? [duplicate]