संभव डुप्लिकेट:
Is it OK to use “delete this” to delete the current object?अगर आप सी ++ में इसे हटाना क्या होगा
मैं बस कुछ कोड है, जहां वे एक वर्ग समारोह में delete this;
किया है देखा था, मुझे पता है कि यह है एक अच्छा डिजाइन नहीं है, लेकिन यह परिभाषित किया गया है कि क्या होगा, कहें कि कक्षा हमेशा कहीं से एक सूचक है। क्या यह हमेशा सही तरीके से हटा दिया जाएगा?
class A
{
public:
void abort() { delete this; }
};
class B
{
void func() { A* a = new A; a->abort(); }
};
देखें http://stackoverflow.com/questions/447379/what-is-the-use-of-delete-this/447531#447531 – icecrime
लिंक्ड पोस्ट संबंधित हैं, लेकिन डुप्लीकेट नहीं लगते हैं। –