当前位置:网站首页>Dynamic memory and smart pointer
Dynamic memory and smart pointer
2022-07-29 01:54:00 【Matches - People】
One 、 Three memory areas
Two 、 Dynamic memory and smart pointer
1、 Operator new、delete
2、shared_ptr class

#include<memory>
#include<string>
using namespace std;
int main()
{
shared_ptr<string> p;
// If p Not empty , Check if it points to an empty string
if (p && p->empty())
{
}
return 0;
}

#include<memory>
#include<string>
#include"test.h"
#include"testClass.h"
using namespace std;
void f(testClass* p)
{
cout << "f" << endl;
delete p;
}
int main()
{
testClass* p;
if (true)
{
shared_ptr<testClass> sp(new testClass("123"),f);
p = sp.get();
}
p->name = "456";// And release , Cannot execute correctly
return 0;
}

shared_ptr<string> p1 = make_shared<string>();
auto p2 = make_shared<string>("CDA");3、unique_ptr class






4、weak_ptr

weak_ptr<string> wp(make_shared<string>("123"));
if (auto sp = wp.lock())// Determine whether it is null
{
}5、 Use standard
边栏推荐
- golang启动报错【已解决】
- Make logic an optimization example in sigma DSP - data distributor
- Analyze OP based on autoware_ global_ Planner global path planning module re planning
- Regular filtering data learning notes (①)
- The brutal rule of blackmail software continues, and attacks increase by 105%
- [7.21-26] code source - [sports festival] [Dan fishing war] [maximum weight division]
- Slow storage scheme
- We summarized the three recommendations for the use of Nacos and first published the Nacos 3.0 plan for the 4th anniversary of the open source of Nacos
- Making high-precision map based on autoware (V)
- 【7.21-26】代码源 - 【好序列】【社交圈】【namonamo】
猜你喜欢

The brutal rule of blackmail software continues, and attacks increase by 105%

We summarized the three recommendations for the use of Nacos and first published the Nacos 3.0 plan for the 4th anniversary of the open source of Nacos

JS 定时器setInterval clearInterval 延时器setTimeOut 异步 动画

【流放之路-第四章】

规划数学期末考试模拟二

【Golang】- runtime.Goexit()

Analysys analysis: focus on users, improve the user experience of mobile banking, and help the growth of user value
![About df['a column name'] [serial number]](/img/e2/179fb4eda695726e87bb483f65e04e.png)
About df['a column name'] [serial number]

Day01作业

活动速递| Apache Doris 性能优化实战系列直播课程初公开,诚邀您来参加!
随机推荐
Explanation of yocto project directory structure
DSP震动座椅
[7.27] code source - [deletion], [bracket sequence], [number replacement], [game], [painting]
It is found that the data of decimal type in the database can be obtained through resultset.getdouble, but this attribute cannot be obtained through GetObject.
How many of the top ten test tools in 2022 do you master
Secret skill winter tide branding skill matching
【流放之路-第四章】
Data platform data access practice
What are the common cyber threats faced by manufacturers and how do they protect themselves
Golang startup error [resolved]
More interesting Title Dynamic Effect
Tda75610-i2c-determination of I2C address of analog power amplifier
How to choose professional, safe and high-performance remote control software
StoneDB 邀请您参与开源社区月会!
Reinforcement learning (I): Q-learning, with source code interpretation
Yocto project download and compilation
Planning mathematics final simulation exam I
Analyze OP based on autoware_ global_ Planner global path planning module re planning
With the explosive growth of digital identity in 2022, global organizations are facing greater network security
T-sne dimensionality reduction