#include <iostream>
using namespace std;


struct A{
   A(){cout<<"+A "<<this<<endl;}
   ~A(){cout<<"-A "<<this<<endl;}
   virtual void test(){}
   void ad(){
      cout<<*(void**)this<<" "<<endl;
   }
};
struct B:A{
   B(){cout<<"+B "<<this<<endl;}
   ~B(){cout<<"-B "<<this<<endl;}
   virtual void test(){}
};
void* operator new  ( std::size_t count ){
   void* r=malloc(count);
   cout<<"new_1 "<<count<<" = "<<r<<endl;
   return r;
}
void operator delete  (void* r){
   cout<<"delete_1 "<<" = "<<r<<endl;
   free(r);
}
void operator delete  (void* r, std::size_t count ){
   cout<<"delete_2 "<<count<<" = "<<r<<endl;
   free(r);
}

int main(){
   cout<<sizeof(A)<<" "<<sizeof(B)<<endl<<endl;
   {
      B* b=new B;
      A* a=b;
      a->A::ad();
      b->B::ad();
      delete a;//Удаляю как a
   }
   cout<<endl<<endl;
   {
      B* b=new B;
      A* a=b;
      a->A::ad();
      b->B::ad();
      delete b;//Удаляю как b
   }
   cout<<endl<<endl;
   {
      B* b=new B;
      A* a=b;
      void* v=b;
      a->A::ad();
      b->B::ad();
      delete v;//Удаляю как void*
   }
}
