Question:
In C++, which smart pointer allows multiple pointers to share ownership of the same dynamically allocated object using reference counting?
C++ में कौन सा स्मार्ट पॉइंटर संदर्भ गणना (reference counting) का उपयोग करके कई पॉइंटर्स को एक ही गतिशील रूप से आवंटित ऑब्जेक्ट के स्वामित्व को साझा करने की अनुमति देता है?
Options:
std::shared_ptrstd::unique_ptrstd::weak_ptrstd::auto_ptr
std::shared_ptrstd::unique_ptrstd::weak_ptrstd::auto_ptr
Correct Answer: a)
Explanation:
std::shared_ptr retains shared ownership of an object through a control block containing a reference count. When the last shared_ptr goes out of scope, the managed object is destroyed.
std::shared_ptr रेफरेंस काउंट का उपयोग करता है जिससे कई पॉइंटर्स एक ही ऑब्जेक्ट को साझा कर सकते हैं। अंतिम पॉइंटर समाप्त होने पर मेमोरी स्वतः मुक्त हो जाती है।