CINXE.COM
Smart pointer - Wikipedia
<!DOCTYPE html> <html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available" lang="en" dir="ltr"> <head> <meta charset="UTF-8"> <title>Smart pointer - Wikipedia</title> <script>(function(){var className="client-js vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available";var cookie=document.cookie.match(/(?:^|; )enwikimwclientpreferences=([^;]+)/);if(cookie){cookie[1].split('%2C').forEach(function(pref){className=className.replace(new RegExp('(^| )'+pref.replace(/-clientpref-\w+$|[^\w-]+/g,'')+'-clientpref-\\w+( |$)'),'$1'+pref+'$2');});}document.documentElement.className=className;}());RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy", "wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"b16fc904-61d0-4e47-9a51-f8f72a108b25","wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"Smart_pointer","wgTitle":"Smart pointer","wgCurRevisionId":1227139870,"wgRevisionId":1227139870,"wgArticleId":319861,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Articles with short description","Short description is different from Wikidata","Articles needing additional references from June 2015","All articles needing additional references","Use dmy dates from July 2022","Use list-defined references from July 2022","All articles with unsourced statements","Articles with unsourced statements from September 2016","Articles with unsourced statements from January 2014","Articles with example C++ code","Data types","Pointers (computer programming)" ],"wgPageViewLanguage":"en","wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"Smart_pointer","wgRelevantArticleId":319861,"wgIsProbablyEditable":true,"wgRelevantPageIsProbablyEditable":true,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgNoticeProject":"wikipedia","wgCiteReferencePreviewsActive":false,"wgFlaggedRevsParams":{"tags":{"status":{"levels":1}}},"wgMediaViewerOnClick":true,"wgMediaViewerEnabledByDefault":true,"wgPopupsFlags":0,"wgVisualEditor":{"pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgMFDisplayWikibaseDescriptions":{"search":true,"watchlist":true,"tagline":false,"nearby":true},"wgWMESchemaEditAttemptStepOversample":false,"wgWMEPageLength":20000,"wgRelatedArticlesCompat":[],"wgCentralAuthMobileDomain":false,"wgEditSubmitButtonLabelPublish":true,"wgULSPosition":"interlanguage","wgULSisCompactLinksEnabled":false,"wgVector2022LanguageInHeader":true,"wgULSisLanguageSelectorEmpty":false,"wgWikibaseItemId": "Q1665677","wgCheckUserClientHintsHeadersJsApi":["brands","architecture","bitness","fullVersionList","mobile","model","platform","platformVersion"],"GEHomepageSuggestedEditsEnableTopics":true,"wgGETopicsMatchModeEnabled":false,"wgGEStructuredTaskRejectionReasonTextInputEnabled":false,"wgGELevelingUpEnabledForUser":false};RLSTATE={"ext.globalCssJs.user.styles":"ready","site.styles":"ready","user.styles":"ready","ext.globalCssJs.user":"ready","user":"ready","user.options":"loading","ext.cite.styles":"ready","ext.pygments":"ready","skins.vector.search.codex.styles":"ready","skins.vector.styles":"ready","skins.vector.icons":"ready","ext.wikimediamessages.styles":"ready","ext.visualEditor.desktopArticleTarget.noscript":"ready","ext.uls.interlanguage":"ready","wikibase.client.init":"ready","ext.wikimediaBadges":"ready"};RLPAGEMODULES=["ext.cite.ux-enhancements","ext.pygments.view","site","mediawiki.page.ready","mediawiki.toc","skins.vector.js","ext.centralNotice.geoIP", "ext.centralNotice.startUp","ext.gadget.ReferenceTooltips","ext.gadget.switcher","ext.urlShortener.toolbar","ext.centralauth.centralautologin","mmv.bootstrap","ext.popups","ext.visualEditor.desktopArticleTarget.init","ext.visualEditor.targetLoader","ext.echo.centralauth","ext.eventLogging","ext.wikimediaEvents","ext.navigationTiming","ext.uls.interface","ext.cx.eventlogging.campaigns","ext.cx.uls.quick.actions","wikibase.client.vector-2022","ext.checkUser.clientHints","ext.growthExperiments.SuggestedEditSession","wikibase.sidebar.tracking"];</script> <script>(RLQ=window.RLQ||[]).push(function(){mw.loader.impl(function(){return["user.options@12s5i",function($,jQuery,require,module){mw.user.tokens.set({"patrolToken":"+\\","watchToken":"+\\","csrfToken":"+\\"}); }];});});</script> <link rel="stylesheet" href="/w/load.php?lang=en&modules=ext.cite.styles%7Cext.pygments%2CwikimediaBadges%7Cext.uls.interlanguage%7Cext.visualEditor.desktopArticleTarget.noscript%7Cext.wikimediamessages.styles%7Cskins.vector.icons%2Cstyles%7Cskins.vector.search.codex.styles%7Cwikibase.client.init&only=styles&skin=vector-2022"> <script async="" src="/w/load.php?lang=en&modules=startup&only=scripts&raw=1&skin=vector-2022"></script> <meta name="ResourceLoaderDynamicStyles" content=""> <link rel="stylesheet" href="/w/load.php?lang=en&modules=site.styles&only=styles&skin=vector-2022"> <meta name="generator" content="MediaWiki 1.44.0-wmf.4"> <meta name="referrer" content="origin"> <meta name="referrer" content="origin-when-cross-origin"> <meta name="robots" content="max-image-preview:standard"> <meta name="format-detection" content="telephone=no"> <meta name="viewport" content="width=1120"> <meta property="og:title" content="Smart pointer - Wikipedia"> <meta property="og:type" content="website"> <link rel="preconnect" href="//upload.wikimedia.org"> <link rel="alternate" media="only screen and (max-width: 640px)" href="//en.m.wikipedia.org/wiki/Smart_pointer"> <link rel="alternate" type="application/x-wiki" title="Edit this page" href="/w/index.php?title=Smart_pointer&action=edit"> <link rel="apple-touch-icon" href="/static/apple-touch/wikipedia.png"> <link rel="icon" href="/static/favicon/wikipedia.ico"> <link rel="search" type="application/opensearchdescription+xml" href="/w/rest.php/v1/search" title="Wikipedia (en)"> <link rel="EditURI" type="application/rsd+xml" href="//en.wikipedia.org/w/api.php?action=rsd"> <link rel="canonical" href="https://en.wikipedia.org/wiki/Smart_pointer"> <link rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en"> <link rel="alternate" type="application/atom+xml" title="Wikipedia Atom feed" href="/w/index.php?title=Special:RecentChanges&feed=atom"> <link rel="dns-prefetch" href="//meta.wikimedia.org" /> <link rel="dns-prefetch" href="//login.wikimedia.org"> </head> <body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject mw-editable page-Smart_pointer rootpage-Smart_pointer skin-vector-2022 action-view"><a class="mw-jump-link" href="#bodyContent">Jump to content</a> <div class="vector-header-container"> <header class="vector-header mw-header"> <div class="vector-header-start"> <nav class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-dropdown" class="vector-dropdown vector-main-menu-dropdown vector-button-flush-left vector-button-flush-right" > <input type="checkbox" id="vector-main-menu-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-main-menu-dropdown" class="vector-dropdown-checkbox " aria-label="Main menu" > <label id="vector-main-menu-dropdown-label" for="vector-main-menu-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-menu mw-ui-icon-wikimedia-menu"></span> <span class="vector-dropdown-label-text">Main menu</span> </label> <div class="vector-dropdown-content"> <div id="vector-main-menu-unpinned-container" class="vector-unpinned-container"> <div id="vector-main-menu" class="vector-main-menu vector-pinnable-element"> <div class="vector-pinnable-header vector-main-menu-pinnable-header vector-pinnable-header-unpinned" data-feature-name="main-menu-pinned" data-pinnable-element-id="vector-main-menu" data-pinned-container-id="vector-main-menu-pinned-container" data-unpinned-container-id="vector-main-menu-unpinned-container" > <div class="vector-pinnable-header-label">Main menu</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-main-menu.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-main-menu.unpin">hide</button> </div> <div id="p-navigation" class="vector-menu mw-portlet mw-portlet-navigation" > <div class="vector-menu-heading"> Navigation </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-mainpage-description" class="mw-list-item"><a href="/wiki/Main_Page" title="Visit the main page [z]" accesskey="z"><span>Main page</span></a></li><li id="n-contents" class="mw-list-item"><a href="/wiki/Wikipedia:Contents" title="Guides to browsing Wikipedia"><span>Contents</span></a></li><li id="n-currentevents" class="mw-list-item"><a href="/wiki/Portal:Current_events" title="Articles related to current events"><span>Current events</span></a></li><li id="n-randompage" class="mw-list-item"><a href="/wiki/Special:Random" title="Visit a randomly selected article [x]" accesskey="x"><span>Random article</span></a></li><li id="n-aboutsite" class="mw-list-item"><a href="/wiki/Wikipedia:About" title="Learn about Wikipedia and how it works"><span>About Wikipedia</span></a></li><li id="n-contactpage" class="mw-list-item"><a href="//en.wikipedia.org/wiki/Wikipedia:Contact_us" title="How to contact Wikipedia"><span>Contact us</span></a></li> </ul> </div> </div> <div id="p-interaction" class="vector-menu mw-portlet mw-portlet-interaction" > <div class="vector-menu-heading"> Contribute </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-help" class="mw-list-item"><a href="/wiki/Help:Contents" title="Guidance on how to use and edit Wikipedia"><span>Help</span></a></li><li id="n-introduction" class="mw-list-item"><a href="/wiki/Help:Introduction" title="Learn how to edit Wikipedia"><span>Learn to edit</span></a></li><li id="n-portal" class="mw-list-item"><a href="/wiki/Wikipedia:Community_portal" title="The hub for editors"><span>Community portal</span></a></li><li id="n-recentchanges" class="mw-list-item"><a href="/wiki/Special:RecentChanges" title="A list of recent changes to Wikipedia [r]" accesskey="r"><span>Recent changes</span></a></li><li id="n-upload" class="mw-list-item"><a href="/wiki/Wikipedia:File_upload_wizard" title="Add images or other media for use on Wikipedia"><span>Upload file</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> <a href="/wiki/Main_Page" class="mw-logo"> <img class="mw-logo-icon" src="/static/images/icons/wikipedia.png" alt="" aria-hidden="true" height="50" width="50"> <span class="mw-logo-container skin-invert"> <img class="mw-logo-wordmark" alt="Wikipedia" src="/static/images/mobile/copyright/wikipedia-wordmark-en.svg" style="width: 7.5em; height: 1.125em;"> <img class="mw-logo-tagline" alt="The Free Encyclopedia" src="/static/images/mobile/copyright/wikipedia-tagline-en.svg" width="117" height="13" style="width: 7.3125em; height: 0.8125em;"> </span> </a> </div> <div class="vector-header-end"> <div id="p-search" role="search" class="vector-search-box-vue vector-search-box-collapses vector-search-box-show-thumbnail vector-search-box-auto-expand-width vector-search-box"> <a href="/wiki/Special:Search" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only search-toggle" title="Search Wikipedia [f]" accesskey="f"><span class="vector-icon mw-ui-icon-search mw-ui-icon-wikimedia-search"></span> <span>Search</span> </a> <div class="vector-typeahead-search-container"> <div class="cdx-typeahead-search cdx-typeahead-search--show-thumbnail cdx-typeahead-search--auto-expand-width"> <form action="/w/index.php" id="searchform" class="cdx-search-input cdx-search-input--has-end-button"> <div id="simpleSearch" class="cdx-search-input__input-wrapper" data-search-loc="header-moved"> <div class="cdx-text-input cdx-text-input--has-start-icon"> <input class="cdx-text-input__input" type="search" name="search" placeholder="Search Wikipedia" aria-label="Search Wikipedia" autocapitalize="sentences" title="Search Wikipedia [f]" accesskey="f" id="searchInput" > <span class="cdx-text-input__icon cdx-text-input__start-icon"></span> </div> <input type="hidden" name="title" value="Special:Search"> </div> <button class="cdx-button cdx-search-input__end-button">Search</button> </form> </div> </div> </div> <nav class="vector-user-links vector-user-links-wide" aria-label="Personal tools"> <div class="vector-user-links-main"> <div id="p-vector-user-menu-preferences" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-userpage" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-dropdown" class="vector-dropdown " title="Change the appearance of the page's font size, width, and color" > <input type="checkbox" id="vector-appearance-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-appearance-dropdown" class="vector-dropdown-checkbox " aria-label="Appearance" > <label id="vector-appearance-dropdown-label" for="vector-appearance-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-appearance mw-ui-icon-wikimedia-appearance"></span> <span class="vector-dropdown-label-text">Appearance</span> </label> <div class="vector-dropdown-content"> <div id="vector-appearance-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <div id="p-vector-user-menu-notifications" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-overflow" class="vector-menu mw-portlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="https://donate.wikimedia.org/wiki/Special:FundraiserRedirector?utm_source=donate&utm_medium=sidebar&utm_campaign=C13_en.wikipedia.org&uselang=en" class=""><span>Donate</span></a> </li> <li id="pt-createaccount-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:CreateAccount&returnto=Smart+pointer" title="You are encouraged to create an account and log in; however, it is not mandatory" class=""><span>Create account</span></a> </li> <li id="pt-login-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:UserLogin&returnto=Smart+pointer" title="You're encouraged to log in; however, it's not mandatory. [o]" accesskey="o" class=""><span>Log in</span></a> </li> </ul> </div> </div> </div> <div id="vector-user-links-dropdown" class="vector-dropdown vector-user-menu vector-button-flush-right vector-user-menu-logged-out" title="Log in and more options" > <input type="checkbox" id="vector-user-links-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-user-links-dropdown" class="vector-dropdown-checkbox " aria-label="Personal tools" > <label id="vector-user-links-dropdown-label" for="vector-user-links-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-ellipsis mw-ui-icon-wikimedia-ellipsis"></span> <span class="vector-dropdown-label-text">Personal tools</span> </label> <div class="vector-dropdown-content"> <div id="p-personal" class="vector-menu mw-portlet mw-portlet-personal user-links-collapsible-item" title="User menu" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport" class="user-links-collapsible-item mw-list-item"><a href="https://donate.wikimedia.org/wiki/Special:FundraiserRedirector?utm_source=donate&utm_medium=sidebar&utm_campaign=C13_en.wikipedia.org&uselang=en"><span>Donate</span></a></li><li id="pt-createaccount" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:CreateAccount&returnto=Smart+pointer" title="You are encouraged to create an account and log in; however, it is not mandatory"><span class="vector-icon mw-ui-icon-userAdd mw-ui-icon-wikimedia-userAdd"></span> <span>Create account</span></a></li><li id="pt-login" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:UserLogin&returnto=Smart+pointer" title="You're encouraged to log in; however, it's not mandatory. [o]" accesskey="o"><span class="vector-icon mw-ui-icon-logIn mw-ui-icon-wikimedia-logIn"></span> <span>Log in</span></a></li> </ul> </div> </div> <div id="p-user-menu-anon-editor" class="vector-menu mw-portlet mw-portlet-user-menu-anon-editor" > <div class="vector-menu-heading"> Pages for logged out editors <a href="/wiki/Help:Introduction" aria-label="Learn more about editing"><span>learn more</span></a> </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-anoncontribs" class="mw-list-item"><a href="/wiki/Special:MyContributions" title="A list of edits made from this IP address [y]" accesskey="y"><span>Contributions</span></a></li><li id="pt-anontalk" class="mw-list-item"><a href="/wiki/Special:MyTalk" title="Discussion about edits from this IP address [n]" accesskey="n"><span>Talk</span></a></li> </ul> </div> </div> </div> </div> </nav> </div> </header> </div> <div class="mw-page-container"> <div class="mw-page-container-inner"> <div class="vector-sitenotice-container"> <div id="siteNotice"><!-- CentralNotice --></div> </div> <div class="vector-column-start"> <div class="vector-main-menu-container"> <div id="mw-navigation"> <nav id="mw-panel" class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-pinned-container" class="vector-pinned-container"> </div> </nav> </div> </div> <div class="vector-sticky-pinned-container"> <nav id="mw-panel-toc" aria-label="Contents" data-event-name="ui.sidebar-toc" class="mw-table-of-contents-container vector-toc-landmark"> <div id="vector-toc-pinned-container" class="vector-pinned-container"> <div id="vector-toc" class="vector-toc vector-pinnable-element"> <div class="vector-pinnable-header vector-toc-pinnable-header vector-pinnable-header-pinned" data-feature-name="toc-pinned" data-pinnable-element-id="vector-toc" > <h2 class="vector-pinnable-header-label">Contents</h2> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-toc.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-toc.unpin">hide</button> </div> <ul class="vector-toc-contents" id="mw-panel-toc-list"> <li id="toc-mw-content-text" class="vector-toc-list-item vector-toc-level-1"> <a href="#" class="vector-toc-link"> <div class="vector-toc-text">(Top)</div> </a> </li> <li id="toc-History" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#History"> <div class="vector-toc-text"> <span class="vector-toc-numb">1</span> <span>History</span> </div> </a> <ul id="toc-History-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Features" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Features"> <div class="vector-toc-text"> <span class="vector-toc-numb">2</span> <span>Features</span> </div> </a> <ul id="toc-Features-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Creating_new_objects" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Creating_new_objects"> <div class="vector-toc-text"> <span class="vector-toc-numb">3</span> <span>Creating new objects</span> </div> </a> <ul id="toc-Creating_new_objects-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-unique_ptr" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#unique_ptr"> <div class="vector-toc-text"> <span class="vector-toc-numb">4</span> <span>unique_ptr</span> </div> </a> <ul id="toc-unique_ptr-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-shared_ptr_and_weak_ptr" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#shared_ptr_and_weak_ptr"> <div class="vector-toc-text"> <span class="vector-toc-numb">5</span> <span>shared_ptr and weak_ptr</span> </div> </a> <ul id="toc-shared_ptr_and_weak_ptr-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Other_types_of_smart_pointers" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Other_types_of_smart_pointers"> <div class="vector-toc-text"> <span class="vector-toc-numb">6</span> <span>Other types of smart pointers</span> </div> </a> <ul id="toc-Other_types_of_smart_pointers-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-See_also" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#See_also"> <div class="vector-toc-text"> <span class="vector-toc-numb">7</span> <span>See also</span> </div> </a> <ul id="toc-See_also-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-References" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#References"> <div class="vector-toc-text"> <span class="vector-toc-numb">8</span> <span>References</span> </div> </a> <ul id="toc-References-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Further_reading" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Further_reading"> <div class="vector-toc-text"> <span class="vector-toc-numb">9</span> <span>Further reading</span> </div> </a> <ul id="toc-Further_reading-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-External_links" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#External_links"> <div class="vector-toc-text"> <span class="vector-toc-numb">10</span> <span>External links</span> </div> </a> <ul id="toc-External_links-sublist" class="vector-toc-list"> </ul> </li> </ul> </div> </div> </nav> </div> </div> <div class="mw-content-container"> <main id="content" class="mw-body"> <header class="mw-body-header vector-page-titlebar"> <nav aria-label="Contents" class="vector-toc-landmark"> <div id="vector-page-titlebar-toc" class="vector-dropdown vector-page-titlebar-toc vector-button-flush-left" > <input type="checkbox" id="vector-page-titlebar-toc-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-titlebar-toc" class="vector-dropdown-checkbox " aria-label="Toggle the table of contents" > <label id="vector-page-titlebar-toc-label" for="vector-page-titlebar-toc-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-listBullet mw-ui-icon-wikimedia-listBullet"></span> <span class="vector-dropdown-label-text">Toggle the table of contents</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-titlebar-toc-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <h1 id="firstHeading" class="firstHeading mw-first-heading"><span class="mw-page-title-main">Smart pointer</span></h1> <div id="p-lang-btn" class="vector-dropdown mw-portlet mw-portlet-lang" > <input type="checkbox" id="p-lang-btn-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-p-lang-btn" class="vector-dropdown-checkbox mw-interlanguage-selector" aria-label="Go to an article in another language. Available in 14 languages" > <label id="p-lang-btn-label" for="p-lang-btn-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--action-progressive mw-portlet-lang-heading-14" aria-hidden="true" ><span class="vector-icon mw-ui-icon-language-progressive mw-ui-icon-wikimedia-language-progressive"></span> <span class="vector-dropdown-label-text">14 languages</span> </label> <div class="vector-dropdown-content"> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li class="interlanguage-link interwiki-ar mw-list-item"><a href="https://ar.wikipedia.org/wiki/%D9%85%D8%A4%D8%B4%D8%B1_%D8%B0%D9%83%D9%8A" title="مؤشر ذكي – Arabic" lang="ar" hreflang="ar" data-title="مؤشر ذكي" data-language-autonym="العربية" data-language-local-name="Arabic" class="interlanguage-link-target"><span>العربية</span></a></li><li class="interlanguage-link interwiki-ca mw-list-item"><a href="https://ca.wikipedia.org/wiki/Punter_intel%C2%B7ligent" title="Punter intel·ligent – Catalan" lang="ca" hreflang="ca" data-title="Punter intel·ligent" data-language-autonym="Català" data-language-local-name="Catalan" class="interlanguage-link-target"><span>Català</span></a></li><li class="interlanguage-link interwiki-cs mw-list-item"><a href="https://cs.wikipedia.org/wiki/Smart_pointer" title="Smart pointer – Czech" lang="cs" hreflang="cs" data-title="Smart pointer" data-language-autonym="Čeština" data-language-local-name="Czech" class="interlanguage-link-target"><span>Čeština</span></a></li><li class="interlanguage-link interwiki-de mw-list-item"><a href="https://de.wikipedia.org/wiki/Intelligenter_Zeiger" title="Intelligenter Zeiger – German" lang="de" hreflang="de" data-title="Intelligenter Zeiger" data-language-autonym="Deutsch" data-language-local-name="German" class="interlanguage-link-target"><span>Deutsch</span></a></li><li class="interlanguage-link interwiki-es mw-list-item"><a href="https://es.wikipedia.org/wiki/Puntero_inteligente" title="Puntero inteligente – Spanish" lang="es" hreflang="es" data-title="Puntero inteligente" data-language-autonym="Español" data-language-local-name="Spanish" class="interlanguage-link-target"><span>Español</span></a></li><li class="interlanguage-link interwiki-fr mw-list-item"><a href="https://fr.wikipedia.org/wiki/Pointeur_intelligent" title="Pointeur intelligent – French" lang="fr" hreflang="fr" data-title="Pointeur intelligent" data-language-autonym="Français" data-language-local-name="French" class="interlanguage-link-target"><span>Français</span></a></li><li class="interlanguage-link interwiki-hy mw-list-item"><a href="https://hy.wikipedia.org/wiki/%D4%BD%D5%A5%D5%AC%D5%A1%D6%81%D5%AB_%D6%81%D5%B8%D6%82%D6%81%D5%AB%D5%B9" title="Խելացի ցուցիչ – Armenian" lang="hy" hreflang="hy" data-title="Խելացի ցուցիչ" data-language-autonym="Հայերեն" data-language-local-name="Armenian" class="interlanguage-link-target"><span>Հայերեն</span></a></li><li class="interlanguage-link interwiki-it mw-list-item"><a href="https://it.wikipedia.org/wiki/Smart_pointer" title="Smart pointer – Italian" lang="it" hreflang="it" data-title="Smart pointer" data-language-autonym="Italiano" data-language-local-name="Italian" class="interlanguage-link-target"><span>Italiano</span></a></li><li class="interlanguage-link interwiki-he mw-list-item"><a href="https://he.wikipedia.org/wiki/%D7%9E%D7%A6%D7%91%D7%99%D7%A2_%D7%97%D7%9B%D7%9D" title="מצביע חכם – Hebrew" lang="he" hreflang="he" data-title="מצביע חכם" data-language-autonym="עברית" data-language-local-name="Hebrew" class="interlanguage-link-target"><span>עברית</span></a></li><li class="interlanguage-link interwiki-pl mw-list-item"><a href="https://pl.wikipedia.org/wiki/Sprytny_wska%C5%BAnik" title="Sprytny wskaźnik – Polish" lang="pl" hreflang="pl" data-title="Sprytny wskaźnik" data-language-autonym="Polski" data-language-local-name="Polish" class="interlanguage-link-target"><span>Polski</span></a></li><li class="interlanguage-link interwiki-pt mw-list-item"><a href="https://pt.wikipedia.org/wiki/Ponteiro_inteligente" title="Ponteiro inteligente – Portuguese" lang="pt" hreflang="pt" data-title="Ponteiro inteligente" data-language-autonym="Português" data-language-local-name="Portuguese" class="interlanguage-link-target"><span>Português</span></a></li><li class="interlanguage-link interwiki-ru mw-list-item"><a href="https://ru.wikipedia.org/wiki/%D0%A3%D0%BC%D0%BD%D1%8B%D0%B9_%D1%83%D0%BA%D0%B0%D0%B7%D0%B0%D1%82%D0%B5%D0%BB%D1%8C" title="Умный указатель – Russian" lang="ru" hreflang="ru" data-title="Умный указатель" data-language-autonym="Русский" data-language-local-name="Russian" class="interlanguage-link-target"><span>Русский</span></a></li><li class="interlanguage-link interwiki-uk mw-list-item"><a href="https://uk.wikipedia.org/wiki/%D0%A0%D0%BE%D0%B7%D1%83%D0%BC%D0%BD%D1%96_%D0%B2%D0%BA%D0%B0%D0%B7%D1%96%D0%B2%D0%BD%D0%B8%D0%BA%D0%B8" title="Розумні вказівники – Ukrainian" lang="uk" hreflang="uk" data-title="Розумні вказівники" data-language-autonym="Українська" data-language-local-name="Ukrainian" class="interlanguage-link-target"><span>Українська</span></a></li><li class="interlanguage-link interwiki-zh mw-list-item"><a href="https://zh.wikipedia.org/wiki/%E6%99%BA%E8%83%BD%E6%8C%87%E9%92%88" title="智能指针 – Chinese" lang="zh" hreflang="zh" data-title="智能指针" data-language-autonym="中文" data-language-local-name="Chinese" class="interlanguage-link-target"><span>中文</span></a></li> </ul> <div class="after-portlet after-portlet-lang"><span class="wb-langlinks-edit wb-langlinks-link"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q1665677#sitelinks-wikipedia" title="Edit interlanguage links" class="wbc-editpage">Edit links</a></span></div> </div> </div> </div> </header> <div class="vector-page-toolbar"> <div class="vector-page-toolbar-container"> <div id="left-navigation"> <nav aria-label="Namespaces"> <div id="p-associated-pages" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-associated-pages" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-nstab-main" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Smart_pointer" title="View the content page [c]" accesskey="c"><span>Article</span></a></li><li id="ca-talk" class="vector-tab-noicon mw-list-item"><a href="/wiki/Talk:Smart_pointer" rel="discussion" title="Discuss improvements to the content page [t]" accesskey="t"><span>Talk</span></a></li> </ul> </div> </div> <div id="vector-variants-dropdown" class="vector-dropdown emptyPortlet" > <input type="checkbox" id="vector-variants-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-variants-dropdown" class="vector-dropdown-checkbox " aria-label="Change language variant" > <label id="vector-variants-dropdown-label" for="vector-variants-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">English</span> </label> <div class="vector-dropdown-content"> <div id="p-variants" class="vector-menu mw-portlet mw-portlet-variants emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> </div> </div> </nav> </div> <div id="right-navigation" class="vector-collapsible"> <nav aria-label="Views"> <div id="p-views" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-views" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-view" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Smart_pointer"><span>Read</span></a></li><li id="ca-edit" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Smart_pointer&action=edit" title="Edit this page [e]" accesskey="e"><span>Edit</span></a></li><li id="ca-history" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Smart_pointer&action=history" title="Past revisions of this page [h]" accesskey="h"><span>View history</span></a></li> </ul> </div> </div> </nav> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-dropdown" class="vector-dropdown vector-page-tools-dropdown" > <input type="checkbox" id="vector-page-tools-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-tools-dropdown" class="vector-dropdown-checkbox " aria-label="Tools" > <label id="vector-page-tools-dropdown-label" for="vector-page-tools-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">Tools</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-tools-unpinned-container" class="vector-unpinned-container"> <div id="vector-page-tools" class="vector-page-tools vector-pinnable-element"> <div class="vector-pinnable-header vector-page-tools-pinnable-header vector-pinnable-header-unpinned" data-feature-name="page-tools-pinned" data-pinnable-element-id="vector-page-tools" data-pinned-container-id="vector-page-tools-pinned-container" data-unpinned-container-id="vector-page-tools-unpinned-container" > <div class="vector-pinnable-header-label">Tools</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-page-tools.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-page-tools.unpin">hide</button> </div> <div id="p-cactions" class="vector-menu mw-portlet mw-portlet-cactions emptyPortlet vector-has-collapsible-items" title="More options" > <div class="vector-menu-heading"> Actions </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-more-view" class="selected vector-more-collapsible-item mw-list-item"><a href="/wiki/Smart_pointer"><span>Read</span></a></li><li id="ca-more-edit" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Smart_pointer&action=edit" title="Edit this page [e]" accesskey="e"><span>Edit</span></a></li><li id="ca-more-history" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Smart_pointer&action=history"><span>View history</span></a></li> </ul> </div> </div> <div id="p-tb" class="vector-menu mw-portlet mw-portlet-tb" > <div class="vector-menu-heading"> General </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="t-whatlinkshere" class="mw-list-item"><a href="/wiki/Special:WhatLinksHere/Smart_pointer" title="List of all English Wikipedia pages containing links to this page [j]" accesskey="j"><span>What links here</span></a></li><li id="t-recentchangeslinked" class="mw-list-item"><a href="/wiki/Special:RecentChangesLinked/Smart_pointer" rel="nofollow" title="Recent changes in pages linked from this page [k]" accesskey="k"><span>Related changes</span></a></li><li id="t-upload" class="mw-list-item"><a href="/wiki/Wikipedia:File_Upload_Wizard" title="Upload files [u]" accesskey="u"><span>Upload file</span></a></li><li id="t-specialpages" class="mw-list-item"><a href="/wiki/Special:SpecialPages" title="A list of all special pages [q]" accesskey="q"><span>Special pages</span></a></li><li id="t-permalink" class="mw-list-item"><a href="/w/index.php?title=Smart_pointer&oldid=1227139870" title="Permanent link to this revision of this page"><span>Permanent link</span></a></li><li id="t-info" class="mw-list-item"><a href="/w/index.php?title=Smart_pointer&action=info" title="More information about this page"><span>Page information</span></a></li><li id="t-cite" class="mw-list-item"><a href="/w/index.php?title=Special:CiteThisPage&page=Smart_pointer&id=1227139870&wpFormIdentifier=titleform" title="Information on how to cite this page"><span>Cite this page</span></a></li><li id="t-urlshortener" class="mw-list-item"><a href="/w/index.php?title=Special:UrlShortener&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FSmart_pointer"><span>Get shortened URL</span></a></li><li id="t-urlshortener-qrcode" class="mw-list-item"><a href="/w/index.php?title=Special:QrCode&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FSmart_pointer"><span>Download QR code</span></a></li> </ul> </div> </div> <div id="p-coll-print_export" class="vector-menu mw-portlet mw-portlet-coll-print_export" > <div class="vector-menu-heading"> Print/export </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="coll-download-as-rl" class="mw-list-item"><a href="/w/index.php?title=Special:DownloadAsPdf&page=Smart_pointer&action=show-download-screen" title="Download this page as a PDF file"><span>Download as PDF</span></a></li><li id="t-print" class="mw-list-item"><a href="/w/index.php?title=Smart_pointer&printable=yes" title="Printable version of this page [p]" accesskey="p"><span>Printable version</span></a></li> </ul> </div> </div> <div id="p-wikibase-otherprojects" class="vector-menu mw-portlet mw-portlet-wikibase-otherprojects" > <div class="vector-menu-heading"> In other projects </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="t-wikibase" class="wb-otherproject-link wb-otherproject-wikibase-dataitem mw-list-item"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q1665677" title="Structured data on this page hosted by Wikidata [g]" accesskey="g"><span>Wikidata item</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> </div> </div> </div> <div class="vector-column-end"> <div class="vector-sticky-pinned-container"> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-pinned-container" class="vector-pinned-container"> </div> </nav> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-pinned-container" class="vector-pinned-container"> <div id="vector-appearance" class="vector-appearance vector-pinnable-element"> <div class="vector-pinnable-header vector-appearance-pinnable-header vector-pinnable-header-pinned" data-feature-name="appearance-pinned" data-pinnable-element-id="vector-appearance" data-pinned-container-id="vector-appearance-pinned-container" data-unpinned-container-id="vector-appearance-unpinned-container" > <div class="vector-pinnable-header-label">Appearance</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-appearance.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-appearance.unpin">hide</button> </div> </div> </div> </nav> </div> </div> <div id="bodyContent" class="vector-body" aria-labelledby="firstHeading" data-mw-ve-target-container> <div class="vector-body-before-content"> <div class="mw-indicators"> </div> <div id="siteSub" class="noprint">From Wikipedia, the free encyclopedia</div> </div> <div id="contentSub"><div id="mw-content-subtitle"></div></div> <div id="mw-content-text" class="mw-body-content"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><div class="shortdescription nomobile noexcerpt noprint searchaux" style="display:none">Data type simulating a pointer with additional features</div> <style data-mw-deduplicate="TemplateStyles:r1251242444">.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}</style><table class="box-More_citations_needed plainlinks metadata ambox ambox-content ambox-Refimprove" role="presentation"><tbody><tr><td class="mbox-image"><div class="mbox-image-div"><span typeof="mw:File"><a href="/wiki/File:Question_book-new.svg" class="mw-file-description"><img alt="" src="//upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/50px-Question_book-new.svg.png" decoding="async" width="50" height="39" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/75px-Question_book-new.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/100px-Question_book-new.svg.png 2x" data-file-width="512" data-file-height="399" /></a></span></div></td><td class="mbox-text"><div class="mbox-text-span">This article <b>needs additional citations for <a href="/wiki/Wikipedia:Verifiability" title="Wikipedia:Verifiability">verification</a></b>.<span class="hide-when-compact"> Please help <a href="/wiki/Special:EditPage/Smart_pointer" title="Special:EditPage/Smart pointer">improve this article</a> by <a href="/wiki/Help:Referencing_for_beginners" title="Help:Referencing for beginners">adding citations to reliable sources</a>. Unsourced material may be challenged and removed.<br /><small><span class="plainlinks"><i>Find sources:</i> <a rel="nofollow" class="external text" href="https://www.google.com/search?as_eq=wikipedia&q=%22Smart+pointer%22">"Smart pointer"</a> – <a rel="nofollow" class="external text" href="https://www.google.com/search?tbm=nws&q=%22Smart+pointer%22+-wikipedia&tbs=ar:1">news</a> <b>·</b> <a rel="nofollow" class="external text" href="https://www.google.com/search?&q=%22Smart+pointer%22&tbs=bkt:s&tbm=bks">newspapers</a> <b>·</b> <a rel="nofollow" class="external text" href="https://www.google.com/search?tbs=bks:1&q=%22Smart+pointer%22+-wikipedia">books</a> <b>·</b> <a rel="nofollow" class="external text" href="https://scholar.google.com/scholar?q=%22Smart+pointer%22">scholar</a> <b>·</b> <a rel="nofollow" class="external text" href="https://www.jstor.org/action/doBasicSearch?Query=%22Smart+pointer%22&acc=on&wc=on">JSTOR</a></span></small></span> <span class="date-container"><i>(<span class="date">June 2015</span>)</i></span><span class="hide-when-compact"><i> (<small><a href="/wiki/Help:Maintenance_template_removal" title="Help:Maintenance template removal">Learn how and when to remove this message</a></small>)</i></span></div></td></tr></tbody></table> <p class="mw-empty-elt"> </p><p>In <a href="/wiki/Computer_science" title="Computer science">computer science</a>, a <b>smart pointer</b> is an <a href="/wiki/Abstract_data_type" title="Abstract data type">abstract data type</a> that simulates a <a href="/wiki/Pointer_(computer_programming)" title="Pointer (computer programming)">pointer</a> while providing added features, such as automatic <a href="/wiki/Memory_management" title="Memory management">memory management</a> or <a href="/wiki/Bounds_checking" title="Bounds checking">bounds checking</a>. Such features are intended to reduce <a href="/wiki/Software_bug" title="Software bug">bugs</a> caused by the misuse of pointers, while retaining efficiency. Smart pointers typically keep track of the memory they point to, and may also be used to manage other resources, such as network connections and <a href="/wiki/File_handle" class="mw-redirect" title="File handle">file handles</a>. Smart pointers were first popularized in the programming language <a href="/wiki/C%2B%2B" title="C++">C++</a> during the first half of the 1990s as rebuttal to criticisms of C++'s lack of <a href="/wiki/Automatic_garbage_collection" class="mw-redirect" title="Automatic garbage collection">automatic garbage collection</a>.<sup id="cite_ref-Kline_1997_1-0" class="reference"><a href="#cite_note-Kline_1997-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-Colvin_1994_2-0" class="reference"><a href="#cite_note-Colvin_1994-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup> </p><p>Pointer misuse can be a major source of bugs. Smart pointers prevent most situations of <a href="/wiki/Memory_leak" title="Memory leak">memory leaks</a> by making the memory deallocation automatic. More generally, they make <a href="/wiki/Object_destruction" class="mw-redirect" title="Object destruction">object destruction</a> automatic: an object controlled by a smart pointer is automatically destroyed (<a href="/wiki/Finalization" class="mw-redirect" title="Finalization">finalized</a> and then deallocated) when the last (or only) owner of an object is destroyed, for example because the owner is a <a href="/wiki/Local_variable" title="Local variable">local variable</a>, and execution leaves the variable's <a href="/wiki/Scope_(programming)" class="mw-redirect" title="Scope (programming)">scope</a>. Smart pointers also eliminate <a href="/wiki/Dangling_pointer" title="Dangling pointer">dangling pointers</a> by postponing destruction until an object is no longer in use. </p><p>If a language supports automatic garbage collection (for example, <a href="/wiki/Java_(programming_language)" title="Java (programming language)">Java</a> or <a href="/wiki/C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a>), then smart pointers are unneeded for reclaiming and safety aspects of memory management, yet are useful for other purposes, such as <a href="/wiki/Cache_(computing)" title="Cache (computing)">cache</a> data structure residence management and <a href="/wiki/Resource_management" title="Resource management">resource management</a> of objects such as file handles or <a href="/wiki/Network_socket" title="Network socket">network sockets</a>. </p><p>Several types of smart pointers exist. Some work with <a href="/wiki/Reference_counting" title="Reference counting">reference counting</a>, others by assigning ownership of an object to one pointer. </p> <meta property="mw:PageProp/toc" /> <div class="mw-heading mw-heading2"><h2 id="History">History</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Smart_pointer&action=edit&section=1" title="Edit section: History"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Even though C++ popularized the concept of smart pointers, especially the <a href="/wiki/Reference_counting" title="Reference counting">reference-counted</a> variety,<sup id="cite_ref-Klabnik-Nichols_2023_3-0" class="reference"><a href="#cite_note-Klabnik-Nichols_2023-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup> the immediate predecessor of one of the languages that inspired C++'s design had reference-counted references built into the language. C++ was inspired in part by <a href="/wiki/Simula67" class="mw-redirect" title="Simula67">Simula67</a>.<sup id="cite_ref-Stroustrup_4-0" class="reference"><a href="#cite_note-Stroustrup-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup> Simula67's ancestor was <a href="/wiki/Simula_I" class="mw-redirect" title="Simula I">Simula I</a>. Insofar as Simula I's <i>element</i> is analogous to C++'s pointer without <i>null</i>, and insofar as Simula I's process with a dummy-statement as its activity body is analogous to C++'s <i>struct</i> (which itself is analogous to <a href="/wiki/C._A._R._Hoare" class="mw-redirect" title="C. A. R. Hoare">C. A. R. Hoare</a>'s <i>record</i> in then-contemporary 1960s work), Simula I had reference counted elements (i.e., pointer-expressions that house indirection) to processes (i.e., records) no later than September 1965, as shown in the quoted paragraphs below.<sup id="cite_ref-Dahl-Nygaard_1966_5-0" class="reference"><a href="#cite_note-Dahl-Nygaard_1966-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup> </p> <blockquote> <p>Processes can be referenced individually. Physically, a process reference is a pointer to an area of memory containing the data local to the process and some additional information defining its current state of execution. However, for reasons stated in the Section 2.2 process references are always indirect, through items called <i>elements.</i> Formally a reference to a process is the value of an expression of type <i>element</i>.<br /> …<br /> <i>element</i> values can be stored and retrieved by assignments and references to <i>element</i> variables and by other means.<br /> The language contains a mechanism for making the attributes of a process accessible from the outside, i.e., from within other processes. This is called remote access- ing. A process is thus a referenceable data structure.<br /> </p><p> It is worth noticing the similarity between a process whose activity body is a dummy statement, and the record concept recently proposed by C. A. R. Hoare and <a href="/wiki/Niklaus_Wirth" title="Niklaus Wirth">N. Wirth</a></p></blockquote> <p>Because C++ borrowed <a href="/wiki/Simula" title="Simula">Simula</a>'s approach to memory allocation—the <i>new</i> keyword when allocating a process/record to obtain a fresh <i>element</i> to that process/record—it is not surprising that C++ eventually resurrected Simula's reference-counted smart-pointer mechanism within <i>element</i> as well. </p> <div class="mw-heading mw-heading2"><h2 id="Features">Features</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Smart_pointer&action=edit&section=2" title="Edit section: Features"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In <a href="/wiki/C%2B%2B" title="C++">C++</a>, a smart pointer is implemented as a template class that mimics, by means of <a href="/wiki/Operator_overloading" title="Operator overloading">operator overloading</a>, the behaviors of a traditional <a href="/wiki/Raw_pointer" class="mw-redirect" title="Raw pointer">(raw) pointer</a>, (e.g. dereferencing, assignment) while providing additional memory management features. </p><p>Smart pointers can facilitate <a href="/wiki/Intentional_programming" title="Intentional programming">intentional programming</a> by expressing, in the type, how the memory of the referent of the pointer will be managed. For example, if a C++ function returns a pointer, there is no way to know whether the caller should delete the memory of the referent when the caller is finished with the information. </p> <div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">SomeType</span><span class="o">*</span><span class="w"> </span><span class="nf">AmbiguousFunction</span><span class="p">();</span><span class="w"> </span><span class="c1">// What should be done with the result?</span> </pre></div> <p>Traditionally, naming conventions have been used to resolve the ambiguity,<sup id="cite_ref-Taligent_6-0" class="reference"><a href="#cite_note-Taligent-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup> which is an error-prone, labor-intensive approach. <a href="/wiki/C%2B%2B11" title="C++11">C++11</a> introduced a way to ensure correct memory management in this case by declaring the function to return a <code>unique_ptr</code>, </p> <div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">std</span><span class="o">::</span><span class="n">unique_ptr</span><span class="o"><</span><span class="n">SomeType</span><span class="o">></span><span class="w"> </span><span class="n">ObviousFunction</span><span class="p">();</span> </pre></div> <p>The declaration of the function return type as a <code>unique_ptr</code> makes explicit the fact that the caller takes ownership of the result, and the C++ runtime ensures that the memory will be reclaimed automatically. Before <a href="/wiki/C%2B%2B11" title="C++11">C++11</a>, unique_ptr can be replaced with <a href="/wiki/Auto_ptr" title="Auto ptr">auto_ptr</a>, which is now deprecated. </p> <div class="mw-heading mw-heading2"><h2 id="Creating_new_objects">Creating new objects</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Smart_pointer&action=edit&section=3" title="Edit section: Creating new objects"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div><p> To ease the allocation of a </p><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">std</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o"><</span><span class="n">SomeType</span><span class="o">></span> </pre></div><p><a href="/wiki/C%2B%2B11" title="C++11">C++11</a> introduced: </p><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="k">auto</span><span class="w"> </span><span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">make_shared</span><span class="o"><</span><span class="n">SomeType</span><span class="o">></span><span class="p">(</span><span class="n">constructor</span><span class="p">,</span><span class="w"> </span><span class="n">parameters</span><span class="p">,</span><span class="w"> </span><span class="n">here</span><span class="p">);</span> </pre></div><p> and similarly </p><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">std</span><span class="o">::</span><span class="n">unique_ptr</span><span class="o"><</span><span class="n">some_type</span><span class="o">></span> </pre></div><p>Since <a href="/wiki/C%2B%2B14" title="C++14">C++14</a> one can use: </p><div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="k">auto</span><span class="w"> </span><span class="n">u</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">make_unique</span><span class="o"><</span><span class="n">SomeType</span><span class="o">></span><span class="p">(</span><span class="n">constructor</span><span class="p">,</span><span class="w"> </span><span class="n">parameters</span><span class="p">,</span><span class="w"> </span><span class="n">here</span><span class="p">);</span> </pre></div> <p>It is preferred, in almost all circumstances, to use these facilities over the <code>new</code> keyword.<sup id="cite_ref-Sutter_2013_7-0" class="reference"><a href="#cite_note-Sutter_2013-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup> </p> <div class="mw-heading mw-heading2"><h2 id="unique_ptr">unique_ptr</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Smart_pointer&action=edit&section=4" title="Edit section: unique_ptr"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/C%2B%2B11" title="C++11">C++11</a> introduces <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">std::unique_ptr</code>, defined in the header <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr"><memory></code>.<sup id="cite_ref-ISO14882_2011_8-0" class="reference"><a href="#cite_note-ISO14882_2011-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup> </p><p>A <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">unique_ptr</code> is a container for a raw pointer, which the <code>unique_ptr</code> is said to own. A <code>unique_ptr</code> explicitly prevents copying of its contained pointer (as would happen with normal assignment), but the <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">std::move</code> function can be used to transfer ownership of the contained pointer to another <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">unique_ptr</code>. A <code>unique_ptr</code> cannot be copied because its copy constructor and assignment operators are explicitly deleted. </p> <div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">std</span><span class="o">::</span><span class="n">unique_ptr</span><span class="o"><</span><span class="kt">int</span><span class="o">></span><span class="w"> </span><span class="n">p1</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="kt">int</span><span class="p">(</span><span class="mi">5</span><span class="p">));</span> <span class="n">std</span><span class="o">::</span><span class="n">unique_ptr</span><span class="o"><</span><span class="kt">int</span><span class="o">></span><span class="w"> </span><span class="n">p2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p1</span><span class="p">;</span><span class="w"> </span><span class="c1">// Compile error.</span> <span class="n">std</span><span class="o">::</span><span class="n">unique_ptr</span><span class="o"><</span><span class="kt">int</span><span class="o">></span><span class="w"> </span><span class="n">p3</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">move</span><span class="p">(</span><span class="n">p1</span><span class="p">);</span><span class="w"> </span><span class="c1">// Transfers ownership. p3 now owns the memory and p1 is set to nullptr.</span> <span class="n">p3</span><span class="p">.</span><span class="n">reset</span><span class="p">();</span><span class="w"> </span><span class="c1">// Deletes the memory.</span> <span class="n">p1</span><span class="p">.</span><span class="n">reset</span><span class="p">();</span><span class="w"> </span><span class="c1">// Does nothing.</span> </pre></div> <p><code>std::<a href="/wiki/Auto_ptr" title="Auto ptr">auto_ptr</a></code> is <a href="/wiki/Deprecation" title="Deprecation">deprecated</a> under C++11 and completely removed from <a href="/wiki/C%2B%2B17" title="C++17">C++17</a>. The copy constructor and assignment operators of <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">auto_ptr</code> do not actually copy the stored pointer. Instead, they <a href="/wiki/Auto_ptr#Semantics" title="Auto ptr">transfer it</a>, leaving the prior <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">auto_ptr</code> object empty. This was one way to implement strict ownership, so that only one <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">auto_ptr</code> object can own the pointer at any given time. This means that <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">auto_ptr</code> should not be used where copy semantics are needed.<sup id="cite_ref-CERT_9-0" class="reference"><a href="#cite_note-CERT-9"><span class="cite-bracket">[</span>9<span class="cite-bracket">]</span></a></sup><sup class="noprint Inline-Template Template-Fact" style="white-space:nowrap;">[<i><a href="/wiki/Wikipedia:Citation_needed" title="Wikipedia:Citation needed"><span title="This claim needs references to reliable sources. (September 2016)">citation needed</span></a></i>]</sup> Since <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">auto_ptr</code> already existed with its copy semantics, it could not be upgraded to be a move-only pointer without breaking <a href="/wiki/Backward_compatibility" title="Backward compatibility">backward compatibility</a> with existing code. </p> <div class="mw-heading mw-heading2"><h2 id="shared_ptr_and_weak_ptr">shared_ptr and weak_ptr</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Smart_pointer&action=edit&section=5" title="Edit section: shared_ptr and weak_ptr"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>C++11 introduces <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">std::shared_ptr</code> and <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">std::weak_ptr</code>, defined in the header <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr"><memory></code>.<sup id="cite_ref-ISO14882_2011_8-1" class="reference"><a href="#cite_note-ISO14882_2011-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup> C++11 also introduces <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">std::make_shared</code> (<code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">std::make_unique</code> was introduced in C++14) to safely allocate dynamic memory in the <a href="/wiki/Resource_acquisition_is_initialization" title="Resource acquisition is initialization">RAII</a> paradigm.<sup id="cite_ref-ISO14882_2014_10-0" class="reference"><a href="#cite_note-ISO14882_2014-10"><span class="cite-bracket">[</span>10<span class="cite-bracket">]</span></a></sup> </p><p>A <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">shared_ptr</code> is a container for a <a href="/wiki/Raw_pointer" class="mw-redirect" title="Raw pointer">raw pointer</a>. It maintains <a href="/wiki/Reference_counting" title="Reference counting">reference counting</a> ownership of its contained pointer in cooperation with all copies of the <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">shared_ptr</code>. An object referenced by the contained raw pointer will be destroyed when and only when all copies of the <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">shared_ptr</code> have been destroyed. </p> <div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">std</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o"><</span><span class="kt">int</span><span class="o">></span><span class="w"> </span><span class="n">p0</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="kt">int</span><span class="p">(</span><span class="mi">5</span><span class="p">));</span><span class="w"> </span><span class="c1">// Valid, allocates 1 integer and initialize it with value 5.</span> <span class="n">std</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o"><</span><span class="kt">int</span><span class="p">[]</span><span class="o">></span><span class="w"> </span><span class="n">p1</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="kt">int</span><span class="p">[</span><span class="mi">5</span><span class="p">]);</span><span class="w"> </span><span class="c1">// Valid, allocates 5 integers.</span> <span class="n">std</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o"><</span><span class="kt">int</span><span class="p">[]</span><span class="o">></span><span class="w"> </span><span class="n">p2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">p1</span><span class="p">;</span><span class="w"> </span><span class="c1">// Both now own the memory.</span> <span class="n">p1</span><span class="p">.</span><span class="n">reset</span><span class="p">();</span><span class="w"> </span><span class="c1">// Memory still exists, due to p2.</span> <span class="n">p2</span><span class="p">.</span><span class="n">reset</span><span class="p">();</span><span class="w"> </span><span class="c1">// Frees the memory, since no one else owns the memory.</span> </pre></div> <p>A <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">weak_ptr</code> is a container for a raw pointer. It is created as a copy of a <code>shared_ptr</code>. The existence or destruction of <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">weak_ptr</code> copies of a <code>shared_ptr</code> have no effect on the <code>shared_ptr</code> or its other copies. After all copies of a <code>shared_ptr</code> have been destroyed, all <code>weak_ptr</code> copies become empty. </p> <div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="n">std</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o"><</span><span class="kt">int</span><span class="o">></span><span class="w"> </span><span class="n">p1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">make_shared</span><span class="o"><</span><span class="kt">int</span><span class="o">></span><span class="p">(</span><span class="mi">5</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">weak_ptr</span><span class="o"><</span><span class="kt">int</span><span class="o">></span><span class="w"> </span><span class="n">wp1</span><span class="w"> </span><span class="p">{</span><span class="n">p1</span><span class="p">};</span><span class="w"> </span><span class="c1">// p1 owns the memory.</span> <span class="p">{</span> <span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o"><</span><span class="kt">int</span><span class="o">></span><span class="w"> </span><span class="n">p2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">wp1</span><span class="p">.</span><span class="n">lock</span><span class="p">();</span><span class="w"> </span><span class="c1">// Now p1 and p2 own the memory.</span> <span class="w"> </span><span class="c1">// p2 is initialized from a weak pointer, so you have to check if the</span> <span class="w"> </span><span class="c1">// memory still exists!</span> <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">p2</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">DoSomethingWith</span><span class="p">(</span><span class="n">p2</span><span class="p">);</span> <span class="w"> </span><span class="p">}</span> <span class="p">}</span> <span class="c1">// p2 is destroyed. Memory is owned by p1.</span> <span class="n">p1</span><span class="p">.</span><span class="n">reset</span><span class="p">();</span><span class="w"> </span><span class="c1">// Free the memory.</span> <span class="n">std</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o"><</span><span class="kt">int</span><span class="o">></span><span class="w"> </span><span class="n">p3</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">wp1</span><span class="p">.</span><span class="n">lock</span><span class="p">();</span><span class="w"> </span> <span class="c1">// Memory is gone, so we get an empty shared_ptr.</span> <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">p3</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="c1">// code will not execute</span> <span class="w"> </span><span class="n">ActionThatNeedsALivePointer</span><span class="p">(</span><span class="n">p3</span><span class="p">);</span> <span class="p">}</span> </pre></div> <p>Because the implementation of <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">shared_ptr</code> uses <a href="/wiki/Reference_counting" title="Reference counting">reference counting</a>, <a href="/wiki/Reference_count#Dealing_with_reference_cycles" class="mw-redirect" title="Reference count">circular references</a> are potentially a problem. A circular <code>shared_ptr</code> chain can be broken by changing the code so that one of the references is a <code>weak_ptr</code>. </p><p>Multiple threads can safely simultaneously access different <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">shared_ptr</code> and <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">weak_ptr</code> objects that point to the same object.<sup id="cite_ref-Boost_11-0" class="reference"><a href="#cite_note-Boost-11"><span class="cite-bracket">[</span>11<span class="cite-bracket">]</span></a></sup> </p><p>The referenced object must be protected separately to ensure <a href="/wiki/Thread_safety" title="Thread safety">thread safety</a>. </p><p><code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">shared_ptr</code> and <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">weak_ptr</code> are based on versions used by the <a href="/wiki/Boost_(C%2B%2B_libraries)" title="Boost (C++ libraries)">Boost libraries</a>.<sup class="noprint Inline-Template Template-Fact" style="white-space:nowrap;">[<i><a href="/wiki/Wikipedia:Citation_needed" title="Wikipedia:Citation needed"><span title="This claim needs references to reliable sources. (January 2014)">citation needed</span></a></i>]</sup> <a href="/wiki/C%2B%2B_Technical_Report_1" title="C++ Technical Report 1">C++ Technical Report 1</a> (TR1) first introduced them to the standard, as <a href="/wiki/C%2B%2B_Technical_Report_1#General_utilities" title="C++ Technical Report 1">general utilities</a>, but C++11 adds more functions, in line with the Boost version. </p> <div class="mw-heading mw-heading2"><h2 id="Other_types_of_smart_pointers">Other types of smart pointers</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Smart_pointer&action=edit&section=6" title="Edit section: Other types of smart pointers"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>There are other types of smart pointers (which are not in the C++ standard) implemented on popular C++ libraries or custom <a href="/wiki/Standard_Template_Library" title="Standard Template Library">STL</a>, some examples include <a href="/wiki/Hazard_pointer" title="Hazard pointer">hazard pointer</a><sup id="cite_ref-12" class="reference"><a href="#cite_note-12"><span class="cite-bracket">[</span>12<span class="cite-bracket">]</span></a></sup> and intrusive pointer.<sup id="cite_ref-13" class="reference"><a href="#cite_note-13"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup> <sup id="cite_ref-14" class="reference"><a href="#cite_note-14"><span class="cite-bracket">[</span>14<span class="cite-bracket">]</span></a></sup> </p> <div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Smart_pointer&action=edit&section=7" title="Edit section: See also"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li><a href="/wiki/Auto_ptr" title="Auto ptr">auto_ptr</a></li> <li><a href="/wiki/Fat_pointer" class="mw-redirect" title="Fat pointer">Fat pointer</a></li> <li><a href="/wiki/Tagged_pointer" title="Tagged pointer">Tagged pointer</a></li> <li><a href="/wiki/Opaque_pointer" title="Opaque pointer">Opaque pointer</a></li> <li><a href="/wiki/Reference_(computer_science)" title="Reference (computer science)">Reference (computer science)</a></li> <li><a href="/wiki/Boost_(C%2B%2B_libraries)" title="Boost (C++ libraries)">Boost (C++ libraries)</a></li> <li><a href="/wiki/Automatic_Reference_Counting" title="Automatic Reference Counting">Automatic Reference Counting</a></li> <li><a href="/wiki/Resource_acquisition_is_initialization" title="Resource acquisition is initialization">Resource acquisition is initialization</a> (RAII)</li> <li><a href="/wiki/Garbage_collection_(computer_science)" title="Garbage collection (computer science)">Garbage collection</a> in computer programming</li></ul> <div class="mw-heading mw-heading2"><h2 id="References">References</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Smart_pointer&action=edit&section=8" title="Edit section: References"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r1239543626">.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}</style><div class="reflist"> <div class="mw-references-wrap mw-references-columns"><ol class="references"> <li id="cite_note-Kline_1997-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-Kline_1997_1-0">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("//upload.wikimedia.org/wikipedia/commons/6/65/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("//upload.wikimedia.org/wikipedia/commons/d/d6/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("//upload.wikimedia.org/wikipedia/commons/a/aa/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("//upload.wikimedia.org/wikipedia/commons/4/4c/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}</style><cite id="CITEREFKline1997" class="citation web cs1">Kline, Marshall (September 1997). <a rel="nofollow" class="external text" href="http://www.cis.usouthal.edu/faculty/drh/c%2B%2Bfaq/freestore-mgmt.html#%5b16.20">"C++ FAQs Lite's sections on reference-counted smart pointers and copy-on-write reference semantics in the freestore management FAQs"</a>. <i>cis.usouthal.edu</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2018-04-06</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=cis.usouthal.edu&rft.atitle=C%2B%2B+FAQs+Lite%27s+sections+on+reference-counted+smart+pointers+and+copy-on-write+reference+semantics+in+the+freestore+management+FAQs&rft.date=1997-09&rft.aulast=Kline&rft.aufirst=Marshall&rft_id=http%3A%2F%2Fwww.cis.usouthal.edu%2Ffaculty%2Fdrh%2Fc%252B%252Bfaq%2Ffreestore-mgmt.html%23%5B16.20&rfr_id=info%3Asid%2Fen.wikipedia.org%3ASmart+pointer" class="Z3988"></span></span> </li> <li id="cite_note-Colvin_1994-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-Colvin_1994_2-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFColvin1994" class="citation web cs1">Colvin, Gregory (1994). <a rel="nofollow" class="external text" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/1994/N0555.pdf">"proposal to standardize counted_ptr in the C++ standard library"</a> <span class="cs1-format">(PDF)</span>. <i>open-std.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2018-04-06</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=open-std.org&rft.atitle=proposal+to+standardize+counted_ptr+in+the+C%2B%2B+standard+library&rft.date=1994&rft.aulast=Colvin&rft.aufirst=Gregory&rft_id=http%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F1994%2FN0555.pdf&rfr_id=info%3Asid%2Fen.wikipedia.org%3ASmart+pointer" class="Z3988"></span></span> </li> <li id="cite_note-Klabnik-Nichols_2023-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-Klabnik-Nichols_2023_3-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFKlabnikNichols2023" class="citation book cs1">Klabnik, Steve; Nichols, Carol (2023) [2018]. "15. Smart Pointers". <i>The Rust Programming Language</i> (2 ed.). San Francisco, California, USA: <a href="/wiki/No_Starch_Press,_Inc." class="mw-redirect" title="No Starch Press, Inc.">No Starch Press, Inc.</a> pp. 315–351. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <a href="/wiki/Special:BookSources/978-1-7185-0310-6" title="Special:BookSources/978-1-7185-0310-6"><bdi>978-1-7185-0310-6</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=bookitem&rft.atitle=15.+Smart+Pointers&rft.btitle=The+Rust+Programming+Language&rft.place=San+Francisco%2C+California%2C+USA&rft.pages=315-351&rft.edition=2&rft.pub=No+Starch+Press%2C+Inc.&rft.date=2023&rft.isbn=978-1-7185-0310-6&rft.aulast=Klabnik&rft.aufirst=Steve&rft.au=Nichols%2C+Carol&rfr_id=info%3Asid%2Fen.wikipedia.org%3ASmart+pointer" class="Z3988"></span> (xxix+1+527+3 pages)</span> </li> <li id="cite_note-Stroustrup-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-Stroustrup_4-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFStroustrup" class="citation web cs1">Stroustrup, Bjarne. <a rel="nofollow" class="external text" href="http://www.stroustrup.com/hopl2.pdf">"A history of C++: 1979–1991"</a> <span class="cs1-format">(PDF)</span><span class="reference-accessdate">. Retrieved <span class="nowrap">2018-04-06</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=unknown&rft.btitle=A+history+of+C%2B%2B%3A+1979%E2%80%931991&rft.aulast=Stroustrup&rft.aufirst=Bjarne&rft_id=http%3A%2F%2Fwww.stroustrup.com%2Fhopl2.pdf&rfr_id=info%3Asid%2Fen.wikipedia.org%3ASmart+pointer" class="Z3988"></span></span> </li> <li id="cite_note-Dahl-Nygaard_1966-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-Dahl-Nygaard_1966_5-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFDahlNygaard1966" class="citation web cs1">Dahl, Ole-Johan; Nygaard, Kristen (September 1966). <a rel="nofollow" class="external text" href="http://folk.uio.no/simula67/Archive/artikkel1966cacm.pdf">"SIMULA—An ALGOL-based simulation language"</a> <span class="cs1-format">(PDF)</span>. <i>folk.uio.no</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2018-04-06</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=folk.uio.no&rft.atitle=SIMULA%E2%80%94An+ALGOL-based+simulation+language&rft.date=1966-09&rft.aulast=Dahl&rft.aufirst=Ole-Johan&rft.au=Nygaard%2C+Kristen&rft_id=http%3A%2F%2Ffolk.uio.no%2Fsimula67%2FArchive%2Fartikkel1966cacm.pdf&rfr_id=info%3Asid%2Fen.wikipedia.org%3ASmart+pointer" class="Z3988"></span></span> </li> <li id="cite_note-Taligent-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-Taligent_6-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://root.cern.ch/TaligentDocs/TaligentOnline/DocumentRoot/1.0/Docs/books/WM/WM_67.html#HEADING81">"Taligent's Guide to Designing Programs, section Use special names for copy, create, and adopt routines"</a>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=unknown&rft.btitle=Taligent%27s+Guide+to+Designing+Programs%2C+section+Use+special+names+for+copy%2C+create%2C+and+adopt+routines&rft_id=https%3A%2F%2Froot.cern.ch%2FTaligentDocs%2FTaligentOnline%2FDocumentRoot%2F1.0%2FDocs%2Fbooks%2FWM%2FWM_67.html%23HEADING81&rfr_id=info%3Asid%2Fen.wikipedia.org%3ASmart+pointer" class="Z3988"></span></span> </li> <li id="cite_note-Sutter_2013-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-Sutter_2013_7-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFSutter2013" class="citation web cs1"><a href="/wiki/Herb_Sutter" title="Herb Sutter">Sutter, Herb</a> (2013-04-20). <a rel="nofollow" class="external text" href="http://isocpp.org/blog/2013/04/trip-report-iso-c-spring-2013-meeting">"Trip Report: ISO C++ Spring 2013 Meeting"</a>. <i>isocpp.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2013-06-14</span></span>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=isocpp.org&rft.atitle=Trip+Report%3A+ISO+C%2B%2B+Spring+2013+Meeting&rft.date=2013-04-20&rft.aulast=Sutter&rft.aufirst=Herb&rft_id=http%3A%2F%2Fisocpp.org%2Fblog%2F2013%2F04%2Ftrip-report-iso-c-spring-2013-meeting&rfr_id=info%3Asid%2Fen.wikipedia.org%3ASmart+pointer" class="Z3988"></span></span> </li> <li id="cite_note-ISO14882_2011-8"><span class="mw-cite-backlink">^ <a href="#cite_ref-ISO14882_2011_8-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-ISO14882_2011_8-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text">ISO 14882:2011 20.7.1</span> </li> <li id="cite_note-CERT-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-CERT_9-0">^</a></b></span> <span class="reference-text">CERT C++ Secure Coding Standard</span> </li> <li id="cite_note-ISO14882_2014-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-ISO14882_2014_10-0">^</a></b></span> <span class="reference-text">ISO 14882:2014 20.7.1</span> </li> <li id="cite_note-Boost-11"><span class="mw-cite-backlink"><b><a href="#cite_ref-Boost_11-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://www.boost.org/libs/smart_ptr/shared_ptr.htm#ThreadSafety">"boost::shared_ptr thread safety"</a>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=unknown&rft.btitle=boost%3A%3Ashared_ptr+thread+safety&rft_id=http%3A%2F%2Fwww.boost.org%2Flibs%2Fsmart_ptr%2Fshared_ptr.htm%23ThreadSafety&rfr_id=info%3Asid%2Fen.wikipedia.org%3ASmart+pointer" class="Z3988"></span> (NB. Does not formally cover std::shared_ptr, but is believed to have the same threading limitations.)</span> </li> <li id="cite_note-12"><span class="mw-cite-backlink"><b><a href="#cite_ref-12">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://github.com/facebook/folly/blob/main/folly/synchronization/Hazptr.h">"folly/Hazptr.h at main · facebook/folly"</a>. <i>github.com</i>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=github.com&rft.atitle=folly%2FHazptr.h+at+main+%C2%B7+facebook%2Ffolly&rft_id=https%3A%2F%2Fgithub.com%2Ffacebook%2Ffolly%2Fblob%2Fmain%2Ffolly%2Fsynchronization%2FHazptr.h&rfr_id=info%3Asid%2Fen.wikipedia.org%3ASmart+pointer" class="Z3988"></span></span> </li> <li id="cite_note-13"><span class="mw-cite-backlink"><b><a href="#cite_ref-13">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.boost.org/doc/libs/1_81_0/libs/smart_ptr/doc/html/smart_ptr.html">"Boost.SmartPtr: The Smart Pointer Library - 1.81.0"</a>. <i>boost.org</i>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=boost.org&rft.atitle=Boost.SmartPtr%3A+The+Smart+Pointer+Library+-+1.81.0&rft_id=https%3A%2F%2Fwww.boost.org%2Fdoc%2Flibs%2F1_81_0%2Flibs%2Fsmart_ptr%2Fdoc%2Fhtml%2Fsmart_ptr.html&rfr_id=info%3Asid%2Fen.wikipedia.org%3ASmart+pointer" class="Z3988"></span></span> </li> <li id="cite_note-14"><span class="mw-cite-backlink"><b><a href="#cite_ref-14">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://github.com/electronicarts/EASTL/blob/master/include/EASTL/intrusive_ptr.h">"EASTL/intrusive_ptr.h at master · electronicarts/EASTL"</a>. <i>github.com</i>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=unknown&rft.jtitle=github.com&rft.atitle=EASTL%2Fintrusive_ptr.h+at+master+%C2%B7+electronicarts%2FEASTL&rft_id=https%3A%2F%2Fgithub.com%2Felectronicarts%2FEASTL%2Fblob%2Fmaster%2Finclude%2FEASTL%2Fintrusive_ptr.h&rfr_id=info%3Asid%2Fen.wikipedia.org%3ASmart+pointer" class="Z3988"></span></span> </li> </ol></div></div> <div class="mw-heading mw-heading2"><h2 id="Further_reading">Further reading</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Smart_pointer&action=edit&section=9" title="Edit section: Further reading"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFMeyers2014" class="citation book cs1"><a href="/wiki/Scott_Meyers" title="Scott Meyers">Meyers, Scott</a> (2014). <i>Effective Modern C++</i>. Sebastopol, California, USA: <a href="/wiki/O%27Reilly_Media" title="O'Reilly Media">O'Reilly Media</a>. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <a href="/wiki/Special:BookSources/978-1-49190399-5" title="Special:BookSources/978-1-49190399-5"><bdi>978-1-49190399-5</bdi></a>. <a href="/wiki/OCLC_(identifier)" class="mw-redirect" title="OCLC (identifier)">OCLC</a> <a rel="nofollow" class="external text" href="https://search.worldcat.org/oclc/884480640">884480640</a>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.btitle=Effective+Modern+C%2B%2B&rft.place=Sebastopol%2C+California%2C+USA&rft.pub=O%27Reilly+Media&rft.date=2014&rft_id=info%3Aoclcnum%2F884480640&rft.isbn=978-1-49190399-5&rft.aulast=Meyers&rft.aufirst=Scott&rfr_id=info%3Asid%2Fen.wikipedia.org%3ASmart+pointer" class="Z3988"></span></li> <li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFAlexandrescu2001" class="citation book cs1"><a href="/wiki/Andrei_Alexandrescu" title="Andrei Alexandrescu">Alexandrescu, Andrei</a> (2001). <a rel="nofollow" class="external text" href="http://www.informit.com/articles/article.aspx?p=25264">"Smart Pointers"</a>. <a href="/wiki/Modern_C%2B%2B_Design" title="Modern C++ Design"><i>Modern C++ Design - Generic Programming and Design Patterns Applied</i></a>. <a href="/wiki/Addison-Wesley" title="Addison-Wesley">Addison-Wesley</a>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=bookitem&rft.atitle=Smart+Pointers&rft.btitle=Modern+C%2B%2B+Design+-+Generic+Programming+and+Design+Patterns+Applied&rft.pub=Addison-Wesley&rft.date=2001&rft.aulast=Alexandrescu&rft.aufirst=Andrei&rft_id=http%3A%2F%2Fwww.informit.com%2Farticles%2Farticle.aspx%3Fp%3D25264&rfr_id=info%3Asid%2Fen.wikipedia.org%3ASmart+pointer" class="Z3988"></span></li> <li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFSutter2002" class="citation web cs1"><a href="/wiki/Herb_Sutter" title="Herb Sutter">Sutter, Herb</a> (2002-08-01). <a rel="nofollow" class="external text" href="http://www.drdobbs.com/184403837/">"The New C++: Smart(er) Pointers"</a>.</cite><span title="ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=unknown&rft.btitle=The+New+C%2B%2B%3A+Smart%28er%29+Pointers&rft.date=2002-08-01&rft.aulast=Sutter&rft.aufirst=Herb&rft_id=http%3A%2F%2Fwww.drdobbs.com%2F184403837%2F&rfr_id=info%3Asid%2Fen.wikipedia.org%3ASmart+pointer" class="Z3988"></span></li> <li><a rel="nofollow" class="external text" href="http://ootips.org/yonat/4dev/smart-pointers.html">Smart Pointers - What, Why, Which?</a>. Yonat Sharon</li> <li><a rel="nofollow" class="external text" href="http://dlugosz.com/Repertoire/refman/Classics/Smart%20Pointers%20Overview.html">Smart Pointers Overview</a>. John M. Dlugosz</li></ul> <div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Smart_pointer&action=edit&section=10" title="Edit section: External links"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li><a rel="nofollow" class="external text" href="http://www.josuttis.com/libbook/cont/countptr.hpp.html">countptr.hpp</a>. <i><a rel="nofollow" class="external text" href="http://www.josuttis.com/libbook/">The C++ Standard Library - A Tutorial and Reference</a></i> by Nicolai M. Josuttis</li> <li><a rel="nofollow" class="external text" href="http://boost.org/libs/smart_ptr/smart_ptr.htm">Boost Smart Pointers</a></li> <li><a rel="nofollow" class="external text" href="http://barrkel.blogspot.com/2008/09/smart-pointers-in-delphi.html">Smart Pointers in Delphi</a></li> <li><a rel="nofollow" class="external text" href="https://doc.rust-lang.org/book/ch15-00-smart-pointers.html">Smart Pointers in Rust</a></li> <li><a rel="nofollow" class="external text" href="http://quant-coder.blogspot.com/2015/12/built-in-smart-pointers-in-modern-c.html">Smart Pointers in Modern C++</a></li></ul> <!-- NewPP limit report Parsed by mw‐web.codfw.main‐f69cdc8f6‐4fsrh Cached time: 20241122143202 Cache expiry: 2592000 Reduced expiry: false Complications: [vary‐revision‐sha1, show‐toc] CPU time usage: 0.396 seconds Real time usage: 0.669 seconds Preprocessor visited node count: 2124/1000000 Post‐expand include size: 38336/2097152 bytes Template argument size: 2800/2097152 bytes Highest expansion depth: 12/100 Expensive parser function count: 40/500 Unstrip recursion depth: 1/20 Unstrip post‐expand size: 59961/5000000 bytes Lua time usage: 0.218/10.000 seconds Lua memory usage: 6334733/52428800 bytes Number of Wikibase entities loaded: 0/400 --> <!-- Transclusion expansion time report (%,ms,calls,template) 100.00% 612.303 1 -total 27.22% 166.675 1 Template:Reflist 21.92% 134.196 11 Template:Cite_web 14.68% 89.888 1 Template:Short_description 12.48% 76.435 1 Template:More_citations_needed 11.60% 71.032 1 Template:Ambox 8.19% 50.137 2 Template:Pagetype 5.81% 35.557 2 Template:Citation_needed 4.78% 29.248 2 Template:Fix 4.20% 25.719 6 Template:Main_other --> <!-- Saved in parser cache with key enwiki:pcache:319861:|#|:idhash:canonical and timestamp 20241122143202 and revision id 1227139870. Rendering was triggered because: page-view --> </div><!--esi <esi:include src="/esitest-fa8a495983347898/content" /> --><noscript><img src="https://login.wikimedia.org/wiki/Special:CentralAutoLogin/start?type=1x1" alt="" width="1" height="1" style="border: none; position: absolute;"></noscript> <div class="printfooter" data-nosnippet="">Retrieved from "<a dir="ltr" href="https://en.wikipedia.org/w/index.php?title=Smart_pointer&oldid=1227139870">https://en.wikipedia.org/w/index.php?title=Smart_pointer&oldid=1227139870</a>"</div></div> <div id="catlinks" class="catlinks" data-mw="interface"><div id="mw-normal-catlinks" class="mw-normal-catlinks"><a href="/wiki/Help:Category" title="Help:Category">Categories</a>: <ul><li><a href="/wiki/Category:Data_types" title="Category:Data types">Data types</a></li><li><a href="/wiki/Category:Pointers_(computer_programming)" title="Category:Pointers (computer programming)">Pointers (computer programming)</a></li></ul></div><div id="mw-hidden-catlinks" class="mw-hidden-catlinks mw-hidden-cats-hidden">Hidden categories: <ul><li><a href="/wiki/Category:Articles_with_short_description" title="Category:Articles with short description">Articles with short description</a></li><li><a href="/wiki/Category:Short_description_is_different_from_Wikidata" title="Category:Short description is different from Wikidata">Short description is different from Wikidata</a></li><li><a href="/wiki/Category:Articles_needing_additional_references_from_June_2015" title="Category:Articles needing additional references from June 2015">Articles needing additional references from June 2015</a></li><li><a href="/wiki/Category:All_articles_needing_additional_references" title="Category:All articles needing additional references">All articles needing additional references</a></li><li><a href="/wiki/Category:Use_dmy_dates_from_July_2022" title="Category:Use dmy dates from July 2022">Use dmy dates from July 2022</a></li><li><a href="/wiki/Category:Use_list-defined_references_from_July_2022" title="Category:Use list-defined references from July 2022">Use list-defined references from July 2022</a></li><li><a href="/wiki/Category:All_articles_with_unsourced_statements" title="Category:All articles with unsourced statements">All articles with unsourced statements</a></li><li><a href="/wiki/Category:Articles_with_unsourced_statements_from_September_2016" title="Category:Articles with unsourced statements from September 2016">Articles with unsourced statements from September 2016</a></li><li><a href="/wiki/Category:Articles_with_unsourced_statements_from_January_2014" title="Category:Articles with unsourced statements from January 2014">Articles with unsourced statements from January 2014</a></li><li><a href="/wiki/Category:Articles_with_example_C%2B%2B_code" title="Category:Articles with example C++ code">Articles with example C++ code</a></li></ul></div></div> </div> </main> </div> <div class="mw-footer-container"> <footer id="footer" class="mw-footer" > <ul id="footer-info"> <li id="footer-info-lastmod"> This page was last edited on 3 June 2024, at 23:23<span class="anonymous-show"> (UTC)</span>.</li> <li id="footer-info-copyright">Text is available under the <a href="/wiki/Wikipedia:Text_of_the_Creative_Commons_Attribution-ShareAlike_4.0_International_License" title="Wikipedia:Text of the Creative Commons Attribution-ShareAlike 4.0 International License">Creative Commons Attribution-ShareAlike 4.0 License</a>; additional terms may apply. By using this site, you agree to the <a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Terms_of_Use" class="extiw" title="foundation:Special:MyLanguage/Policy:Terms of Use">Terms of Use</a> and <a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy" class="extiw" title="foundation:Special:MyLanguage/Policy:Privacy policy">Privacy Policy</a>. Wikipedia® is a registered trademark of the <a rel="nofollow" class="external text" href="https://wikimediafoundation.org/">Wikimedia Foundation, Inc.</a>, a non-profit organization.</li> </ul> <ul id="footer-places"> <li id="footer-places-privacy"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy">Privacy policy</a></li> <li id="footer-places-about"><a href="/wiki/Wikipedia:About">About Wikipedia</a></li> <li id="footer-places-disclaimers"><a href="/wiki/Wikipedia:General_disclaimer">Disclaimers</a></li> <li id="footer-places-contact"><a href="//en.wikipedia.org/wiki/Wikipedia:Contact_us">Contact Wikipedia</a></li> <li id="footer-places-wm-codeofconduct"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Universal_Code_of_Conduct">Code of Conduct</a></li> <li id="footer-places-developers"><a href="https://developer.wikimedia.org">Developers</a></li> <li id="footer-places-statslink"><a href="https://stats.wikimedia.org/#/en.wikipedia.org">Statistics</a></li> <li id="footer-places-cookiestatement"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement">Cookie statement</a></li> <li id="footer-places-mobileview"><a href="//en.m.wikipedia.org/w/index.php?title=Smart_pointer&mobileaction=toggle_view_mobile" class="noprint stopMobileRedirectToggle">Mobile view</a></li> </ul> <ul id="footer-icons" class="noprint"> <li id="footer-copyrightico"><a href="https://wikimediafoundation.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/static/images/footer/wikimedia-button.svg" width="84" height="29" alt="Wikimedia Foundation" loading="lazy"></a></li> <li id="footer-poweredbyico"><a href="https://www.mediawiki.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/w/resources/assets/poweredby_mediawiki.svg" alt="Powered by MediaWiki" width="88" height="31" loading="lazy"></a></li> </ul> </footer> </div> </div> </div> <div class="vector-settings" id="p-dock-bottom"> <ul></ul> </div><script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgHostname":"mw-web.codfw.main-f69cdc8f6-sqbd2","wgBackendResponseTime":158,"wgPageParseReport":{"limitreport":{"cputime":"0.396","walltime":"0.669","ppvisitednodes":{"value":2124,"limit":1000000},"postexpandincludesize":{"value":38336,"limit":2097152},"templateargumentsize":{"value":2800,"limit":2097152},"expansiondepth":{"value":12,"limit":100},"expensivefunctioncount":{"value":40,"limit":500},"unstrip-depth":{"value":1,"limit":20},"unstrip-size":{"value":59961,"limit":5000000},"entityaccesscount":{"value":0,"limit":400},"timingprofile":["100.00% 612.303 1 -total"," 27.22% 166.675 1 Template:Reflist"," 21.92% 134.196 11 Template:Cite_web"," 14.68% 89.888 1 Template:Short_description"," 12.48% 76.435 1 Template:More_citations_needed"," 11.60% 71.032 1 Template:Ambox"," 8.19% 50.137 2 Template:Pagetype"," 5.81% 35.557 2 Template:Citation_needed"," 4.78% 29.248 2 Template:Fix"," 4.20% 25.719 6 Template:Main_other"]},"scribunto":{"limitreport-timeusage":{"value":"0.218","limit":"10.000"},"limitreport-memusage":{"value":6334733,"limit":52428800}},"cachereport":{"origin":"mw-web.codfw.main-f69cdc8f6-4fsrh","timestamp":"20241122143202","ttl":2592000,"transientcontent":false}}});});</script> <script type="application/ld+json">{"@context":"https:\/\/schema.org","@type":"Article","name":"Smart pointer","url":"https:\/\/en.wikipedia.org\/wiki\/Smart_pointer","sameAs":"http:\/\/www.wikidata.org\/entity\/Q1665677","mainEntity":"http:\/\/www.wikidata.org\/entity\/Q1665677","author":{"@type":"Organization","name":"Contributors to Wikimedia projects"},"publisher":{"@type":"Organization","name":"Wikimedia Foundation, Inc.","logo":{"@type":"ImageObject","url":"https:\/\/www.wikimedia.org\/static\/images\/wmf-hor-googpub.png"}},"datePublished":"2003-09-16T18:22:11Z","dateModified":"2024-06-03T23:23:19Z","headline":"abstract data type that simulates a pointer while providing added features, such as automatic memory management or bounds checking, intended to reduce bugs caused by the misuse of pointers, while retaining efficiency"}</script> </body> </html>