当前位置:网站首页>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边栏推荐
- Random numbers in a long range, is that right- Random number in long range, is this the way?
- Summary of learning materials and notes of Zhang Fei's actual combat electronics 1-31
- Help change the socket position of PCB part
- EGO Planner代码解析bspline_optimizer部分(3)
- SQL injection for Web Security (1)
- 第二章:基于分解的求水仙花数,基于组合的求水仙花数, 兰德尔数,求[x,y]内的守形数,探求n位守形数,递推探索n位逐位整除数
- 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
- 记录在模拟器中运行flutter时报的错
- Merge K ascending linked lists
- Compared with 4G, what are the advantages of 5g to meet the technical requirements of industry 4.0
猜你喜欢

Valentine's Day - make an exclusive digital collection for your lover

Free sharing | linefriends hand account inner page | horizontal grid | not for sale

Nous avons fait une plateforme intelligente de règlement de détail

Record the errors reported when running fluent in the simulator

Recommend a GIF processing artifact less than 300K - gifsicle (free download)
![[water quality prediction] water quality prediction based on MATLAB Fuzzy Neural Network [including Matlab source code 1923]](/img/aa/9980acc9839f067202d46faabbf029.png)
[water quality prediction] water quality prediction based on MATLAB Fuzzy Neural Network [including Matlab source code 1923]
![[optics] dielectric constant calculation based on MATLAB [including Matlab source code 1926]](/img/cb/ee696d5a7d6bef96fe0db89e8478ed.jpg)
[optics] dielectric constant calculation based on MATLAB [including Matlab source code 1926]

SQL injection for Web Security (1)

Dart JSON编码器和解码器剖析

Thesis study - 7 Very Deep Convolutional Networks for Large-Scale Image Recognition (3/3)
随机推荐
Valentine's Day - make an exclusive digital collection for your lover
Octopus online ecological chain tour Atocha protocol received near grant worth $50000
第一章: 舍罕王失算
Analyse du Code du planificateur ego bspline Section Optimizer (1)
01. Preparation for automated office (free guidance, only three steps)
第一章:求奇因数代数和,求同吗小数和s(d, n),简化同码小数和s(d, n),拓广同码小数和s(d, n)
How to build an efficient information warehouse
【疾病识别】基于matlab GUI机器视觉肺癌检测系统【含Matlab源码 1922期】
Redis master-slave synchronization, clustering, persistence
OSPF - detailed explanation of stub area and full stub area
[free sharing] kotalog diary2022 plan electronic manual ledger
【水质预测】基于matlab模糊神经网络水质预测【含Matlab源码 1923期】
EGO Planner代码解析bspline_optimizer部分(2)
High concurrency Architecture - read write separation
利用可视化结果,点击出现对应的句子
I didn't cancel
Flutter network and data storage framework construction-b1
How to design a high concurrency system
Scrapy爬虫框架
Think of new ways