#include <iostream>
using namespace std;

class Tracer {
	static int nextid;
	int id; 
public:  
    Tracer () : id(++nextid) {
        cout<<"Tracer "<<id<<" created"<<endl;     	
    }
    ~Tracer() {
         cout<<"Tracer "<<id<<" destroyed"<<endl;     	
    }
};
int Tracer::nextid =0; 

int main()
{
	{
    	struct Simple { Tracer i; } s;
    	s.i.~Tracer();           // not needed if integer. 
    	new (&s.i) Tracer;       // the lifecyle of the newly created object 
        	                     // will auto, since Simple will be destroyed when
            	                 // going out of scope
	}
	cout << "Simple went out of scope"<<endl;
	
	{
    	struct Complex { char s[256]; } c; 
    	Tracer *p = new (&c.s) Tracer;  // the lifecycle of the newly created object 
                            // is dynamic.  You'll need to delete it in time. 
                            // because compiler doesn't know about its true nature
                            // and memory will be lost when going out of scope
        p->~Tracer(); 
    }
	cout << "Complex went out of scope"<<endl;
}