Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::auto_ptr

      From cppreference.com
      <cpp‎ |memory
       
       
      Memory management library
      (exposition only*)
      Allocators
      Uninitialized memory algorithms
      Constrained uninitialized memory algorithms
      Memory resources
      Uninitialized storage(until C++20)
      (until C++20*)
      (until C++20*)
      Garbage collector support(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
       
       
      Defined in header<memory>
      template<class T>class auto_ptr;
      (1)(deprecated in C++11)
      (removed in C++17)
      template<>class auto_ptr<void>;
      (2)(deprecated in C++11)
      (removed in C++17)

      auto_ptr is a smart pointer that manages an object obtained vianew expression and deletes that object whenauto_ptr itself is destroyed. It may be used to provide exception safety for dynamically allocated objects, for passing ownership of dynamically allocated objects into functions and for returning dynamically allocated objects from functions.

      Copying anauto_ptr copies the pointer and transfers ownership to the destination: both copy construction and copy assignment ofauto_ptr modify their right-hand arguments, and the "copy" is not equal to the original. Because of these unusual copy semantics,auto_ptr may not be placed in standard containers.std::unique_ptr is preferred for this and other uses.(since C++11)

      2) Specialization for typevoid is provided, it declares the typedefelement_type, but no member functions.

      An additional class templateauto_ptr_ref is referred to throughout the documentation. It is an implementation-defined type that holds a reference toauto_ptr. The implementation is allowed to provide the template with a different name or implement the functions returning it or accepting it as parameter in other ways.

      Contents

      [edit]Member types

      Member type Definition
      element_typeT

      [edit]Member functions

      creates a newauto_ptr
      (public member function)[edit]
      destroys anauto_ptr and the managed object
      (public member function)[edit]
      transfers ownership from anotherauto_ptr
      (public member function)[edit]
      converts the managed pointer to a pointer to different type
      (public member function)[edit]
      Observers
      returns a pointer to the managed object
      (public member function)[edit]
      accesses the managed object
      (public member function)[edit]
      Modifiers
      replaces the managed object
      (public member function)[edit]
      releases ownership of the managed object
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/memory/auto_ptr&oldid=175388"

      [8]ページ先頭

      ©2009-2025 Movatter.jp