From 2f84e7ed341716f8b3c02d994e6373a1c4a3a47d Mon Sep 17 00:00:00 2001 From: Jidong Xiao Date: Fri, 18 Apr 2025 03:04:04 -0400 Subject: [PATCH] adding member functions --- lectures/27_garbage_collection/README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lectures/27_garbage_collection/README.md b/lectures/27_garbage_collection/README.md index 5401c65..e5bb08d 100644 --- a/lectures/27_garbage_collection/README.md +++ b/lectures/27_garbage_collection/README.md @@ -258,6 +258,22 @@ int main() { } ``` +#### Member Functions and Operators of std::shared_ptr + +- reset() Releases ownership of the managed object. Can also assign a new object. + +- use_count() Returns the number of shared_ptrs sharing ownership of the object. + +- unique() Returns true if this shared_ptr is the only one owning the object (use_count() == 1). + +- get() Returns the raw pointer to the managed object. + +- operator*() Dereferences the pointer (*sp) to access the object. + +- operator->() Accesses a member of the object (sp->member). + +- operator bool() Checks whether the pointer is non-null (if (sp)). + ### 27.14.2 std::unique_ptr - Exclusive ownership of a dynamically allocated object.