G
Guest
I have this class:
---------------------------------------------
class A {
string a;
int instances;
A();
static vector<A> all;
public:
static A *CreateA(...................);
void operator delete(void *tex) {
A *t = (A*) tex;
if (t->instances) t->instances--;
}
static void GarbageCollector();
};
----------------------------------------------
CreateA checks if "string a" exists in any of vector's objects. If exists
increases counter and return Pointer else creates and adds in vector a new
object.
When I run "delete(objectA);" then C++ runs first destructor and after
"delete".
This means that "string a" destroyed.
How can I avoid this? Because in this pointer there are many objects and
"string a" destroyed for all. (avoid to run destructor, but run only
"delete")
Thanks
---------------------------------------------
class A {
string a;
int instances;
A();
static vector<A> all;
public:
static A *CreateA(...................);
void operator delete(void *tex) {
A *t = (A*) tex;
if (t->instances) t->instances--;
}
static void GarbageCollector();
};
----------------------------------------------
CreateA checks if "string a" exists in any of vector's objects. If exists
increases counter and return Pointer else creates and adds in vector a new
object.
When I run "delete(objectA);" then C++ runs first destructor and after
"delete".
This means that "string a" destroyed.
How can I avoid this? Because in this pointer there are many objects and
"string a" destroyed for all. (avoid to run destructor, but run only
"delete")
Thanks