#include <iostream>
#include <vector>
using namespace std;

class C1 {
public: 
    C1() { cout<<"  C1 object constructed"<<endl; } 
    ~C1() { cout<<"  C1 object destroyed"<<endl; }
};
class C2 {
public: 
    C2() { cout<<"  C2 object constructed"<<endl; } 
    ~C2() { cout<<"  C2 object destroyed"<<endl; }
};
 
int main(void) {
	cout<<"Normal array"<<endl; 
	C1 *p = new C1[2];
	delete[] p;     // arrayed delete for arrayed new
	cout<<"Everything was fine !"<<endl<<endl;
	
            cout<<"Array into a good vector"<<endl; 
            {
	   vector<C1*> v; 
	   v.push_back(new C1[2]);  // array of doubles
	   for (auto &x:v)
	       delete[]x; 
	   v.clear();
            } // vector deceases here
	cout<<"Everything is fine"<<endl<<endl;
	
	cout<<"Going via a void*"<<endl; 
	std::vector<void*> data;
	data.push_back(new C1[2]);  // array of doubles
//	data.push_back(new C2[2]);   // array of shorts
	for (auto &x:data)
	       delete[]x; 
	data.clear();
	cout<<"OUCH !!!"<<endl; 
	return 0;
}
 