当前位置:网站首页>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边栏推荐
- 01. Preparation for automated office (free guidance, only three steps)
- Think of new ways
- Valentine's Day - make an exclusive digital collection for your lover
- These problems should be paid attention to in the production of enterprise promotional videos
- OSPF - detailed explanation of stub area and full stub area
- Redis master-slave synchronization, clustering, persistence
- Buuctf's different flags and simplerev
- ActiveMQ的基础
- 我們做了一個智能零售結算平臺
- 【疾病识别】基于matlab GUI机器视觉肺癌检测系统【含Matlab源码 1922期】
猜你喜欢

Thesis study - 7 Very Deep Convolutional Networks for Large-Scale Image Recognition (3/3)

Php based campus lost and found platform (automatic matching push)

What does a really excellent CTO look like in my eyes
![[leetcode] [SQL] notes](/img/8d/160a03b9176b8ccd8d52f59d4bb47f.png)
[leetcode] [SQL] notes
![Free hand account sharing in September - [cream Nebula]](/img/4f/fec31778a56886585e35be87885452.jpg)
Free hand account sharing in September - [cream Nebula]

第二章:4位卡普雷卡数,搜索偶数位卡普雷卡数,搜索n位2段和平方数,m位不含0的巧妙平方数,指定数字组成没有重复数字的7位平方数,求指定区间内的勾股数组,求指定区间内的倒立勾股数组

Buuctf's different flags and simplerev

SSM整合-前后台协议联调(列表功能、添加功能、添加功能状态处理、修改功能、删除功能)

Basic principle of LSM tree
![[disease identification] machine vision lung cancer detection system based on Matlab GUI [including Matlab source code 1922]](/img/fc/00835b95537cf889588502a3d13bc9.png)
[disease identification] machine vision lung cancer detection system based on Matlab GUI [including Matlab source code 1922]
随机推荐
Dart JSON编码器和解码器剖析
[water quality prediction] water quality prediction based on MATLAB Fuzzy Neural Network [including Matlab source code 1923]
02 -- QT OpenGL drawing triangle
SQL injection for Web Security (1)
【LeetCode】【SQL】刷题笔记
Free hand account sharing in September - [cream Nebula]
Leetcode 1189. Maximum number of balloons (special character count)
EGO Planner代码解析bspline_optimizer部分(2)
【数学建模】基于matlab船舶三自由度MMG模型【含Matlab源码 1925期】
第二章:求a,b的最大公约与最小公倍数经典求解,求a,b的最大公约与最小公倍数常规求解,求n个正整数的的最大公约与最小公倍数
Pecan - route
Read the paper glodyne global topology preserving dynamic network embedding
Chapter 1: King Shehan miscalculated
【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁
Day18 - basis of interface testing
Streaming media server (16) -- figure out the difference between live broadcast and on-demand
Flask generates swagger documents
How does if ($variable) work? [repeat] - how exactly does if ($variable) work? [duplicate]
Dynamic planning -- expansion topics
Bad mentality leads to different results