C++ – Confusing with delete and free function in C++

cdelete-operatordestructorfree

Possible Duplicate:
What is the difference between new/delete and malloc/free?

class Foo
   {
    public:
     Foo() { x =  new int; } 
     ~Foo() { delete x; }
    private:
        int *x;
   };

  Foo *p = new Foo[10];
  free ( p );

I am getting confuse with the above code.
Is there any problem about it?

Best Answer

When you call free() for an object allocated with new, its destructor is not called, so in this example you get memory leaks. Also, in this example you must use delete[] because memory is allocated with new[].