Skip to main content
gamedev.net
🔒 Locked

Classes Self-Managing

Started by Wyrframe Dec 28, 2001 at 10:58 PM 0 replies 400+ views
Original Post
Wyrframe
Wyrframe
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?
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
kvh
kvh
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;
}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.