Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Smart pointer Code in C++

2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you the "example analysis of smart pointer code in C++", which is easy to understand and clear. I hope it can help you solve your doubts. Now let the editor lead you to study and study the "sample analysis of smart pointer code in C++".

Preface

If you use new to allocate memory from the heap in your program, you should use delete to free it when it is no longer needed. C++ introduced smart pointer auto_ptr to help automate this process, but aoto_ptr also has its limitations, so three more smart pointer unique_ptr shared_ptr weak_ptr are introduced from the Boost library.

1Magazine aotokinetic ptrash / ConsoleApplication1.cpp: defines the entry point of the console application. / / # include "stdafx.h" # include # include using namespace std;int _ tmain (int argc, _ TCHAR* argv []) {auto_ptr ptr1 ("this is ptr!")); auto_ptr ptr2; ptr2 = ptr1; cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report