当前位置:网站首页>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边栏推荐
- Record the errors reported when running fluent in the simulator
- Sentinel source code analysis part II - sentinel dashboard console startup and configuration
- 利用可视化结果,点击出现对应的句子
- 【LeetCode】【SQL】刷题笔记
- Latex image rotates with title
- Day10 ---- 强制登录, token刷新与jwt禁用
- 第一章:简化同码小数和s(d, n)
- [mathematical modeling] ship three degree of freedom MMG model based on MATLAB [including Matlab source code 1925]
- UE source code analysis: uccharactermovementcomponent - rootmotion
- Flutter network and data storage framework construction-b1
猜你喜欢
第一章:三位阶乘和数,图形点扫描
FBI警告:有人利用AI换脸冒充他人身份进行远程面试
The necessity of lean production and management in sheet metal industry
Think of new ways
[mathematical modeling] ship three degree of freedom MMG model based on MATLAB [including Matlab source code 1925]
Detailed explanation of shuttle unity interworking principle
[water quality prediction] water quality prediction based on MATLAB Fuzzy Neural Network [including Matlab source code 1923]
Why should we do feature normalization / standardization?
[optics] vortex generation based on MATLAB [including Matlab source code 1927]
Php based campus lost and found platform (automatic matching push)
随机推荐
【数学建模】基于matlab船舶三自由度MMG模型【含Matlab源码 1925期】
Today I am filled with emotion
Zhang Fei hardware 90 day learning notes - personal record on day 5. Please see my personal profile / homepage for the complete record
2020 intermediate financial management (escort class)
This Chinese numpy quick look-up table is too easy!
變化是永恒的主題
Pecan — @expose()
Thesis study - 7 Very Deep Convolutional Networks for Large-Scale Image Recognition (3/3)
第一章:求奇因数代数和,求同吗小数和s(d, n),简化同码小数和s(d, n),拓广同码小数和s(d, n)
第一章:三位阶乘和数,图形点扫描
Go home early today
QT -- qfileinfo file information reading
High concurrency architecture cache
Thinking about festivals
Streaming media server (16) -- figure out the difference between live broadcast and on-demand
SQL injection for Web Security (1)
东数西算拉动千亿产业,敢啃“硬骨头”的存储厂商才更有机会
Scrape crawler framework
High concurrency Architecture - separate databases and tables
The space of C disk is insufficient, and the computer becomes stuck. Quickly expand the capacity of C disk to make the system more smooth