ENع
الدرس 18 · Modern C++

Smart pointers: unique_ptr and shared_ptr

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

A smart pointer is a small object that owns heap memory and deletes it in its destructor, so you never write delete. Follow a twelve-line program as std::make_unique creates an int with exactly one owner, std::move hands that ownership over, std::make_shared creates an int with a counted control block, copies raise and lower the use count, and at the end of main every owner frees what it owns, in reverse order, with no leak.

14 دقيقة11 خطوات5 أسئلةAdvanced
شكل 18 · تفاعلي
جارٍ تحميل الرسم…
أو ← →

اختبار يتاح بعد الخطوة الأخيرة.