#include <iostream>
#include <vector>
using namespace std;
//--------------------------------------------------------------------------------
class A
{
public:
A(int data){ m_data = data ; instanc_vec.push_back(this);}
~A()
{
for (int i=0; i<instanc_vec.size(); i++)
{
if(instanc_vec[i]==this)
{
instanc_vec.erase(instanc_vec.begin()+i);
break;
}
}
}
const static vector<A*>& GetObjVec(){ return instanc_vec; }
static int DelObj(int i)
{
if(i<0 || i> instanc_vec.size()-1 ) return -1;
delete instanc_vec[i];
return 1;
}
static int Clear()
{
int res = instanc_vec.size();
for (int i=instanc_vec.size()-1; i>=0; i--)
{
delete instanc_vec[i];
}
return res;
}
int m_data;
private:
static vector<A*> instanc_vec;
};
//--------------------------------------------------------------------------------
void pnt()
{
cout<<"---------------------------------------------"<<endl;
for (int i=0;i<A::GetObjVec().size();i++)
{
cout<<A::GetObjVec()[i]->m_data<<endl;
}
}
//--------------------------------------------------------------------------------
vector<A*> A::instanc_vec;
int main()
{
A* p1= new A(100);
A* p2= new A(200);
A* p3= new A(300);
A* p4= new A(400);
pnt();
delete p3;
pnt();
delete p1;
pnt();
new A(123);
new A(223);
new A(323);
pnt();
A::DelObj(3);
pnt();
A::Clear();
pnt();
return 0;
}