Jump to content
  • Advertisement

Archived

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

Wyrframe

Classes Self-Managing

This topic is 6017 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
Advertisement
here''s an example:

  
#include <iostream>

using namespace std;


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

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

int main() {
C* c = new C;
c->Free();

return 0;
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!