, . , A , undefined, - .
? :
- ( , contructor destructor) . , , A. , , A .
- , . , , .
@zvone , first last .
( ) :
A::~A() {
if(previous != 0) previous->next=next;
if(next != 0) next->previous=previous;
if (first == this) first = next;
if (last == this) last = previous;
}
:
a.h
class A {
public:
static A *first, *last;
A *previous, *next;
static std::mutex mut;
A();
~A();
};
a.cpp:
#include "a.h"
A *A::first=0, *A::last=0;
std::mutex A::mut;
A::A() {
mut.lock()
if(first==0) first=this;
previous=last;
if(previous != 0) previous->next=this;
last=this;
next=0;
mut.unlock();
}
A::~A() {
mut.lock()
if(previous != 0) previous->next=next;
if(next != 0) next->previous=previous;
if (first == this) first = next;
if (last == this) last = previous;
mut.unlock();
}