• Advertisement


This topic is now archived and is closed to further replies.

Classes Self-Managing

This topic is 5928 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The basics are thus... I have a big array of pointers to TILESTACK classes. If a given element is NULL, then there is no TILESTACK, and thus no objects, in that element. A TILESTACK manages a linked list of IObj classes that are in a specific tile. It has this bit of code... // Up in the TILESTACK class declaration... private: long mytile; // Assume that it is set to the array index in which // a pointer to this instance of this class can be found, in // the big array of pointers. // In the code... void TILESTACK::removeitem(IObj* iiQ) { . // iiQ stands for "Item In Question" . // Finds and deletes the passed object. delete gTilelist[mytile]; // Deletes the pointer to this instance of the class. } // And the TILESTACK''s destructor... TILESTACK::~TILESTACK() { gTilelist[mytile] = NULL; } I am seriously wondering if this whole crazy getup will work... can a class delete itself?

Share this post

Link to post
Share on other sites
here''s an example:

#include <iostream>

using namespace std;

class C {
C() { cout << "C created" << endl; }
void Free() { delete this; }

~C() { cout << "C destroyed" << endl; }

int main() {
C* c = new C;

return 0;

Share this post

Link to post
Share on other sites

  • Advertisement