Question: We can call destructor explicitly through class pointer, why not constructor? Any idea?

```
#include <iostream>

class Con {
public:
    Con( int x ) : x( x ) {

    }

private:
    int x;
};

int main() {
    Con* c = new Con( 1 );
    //c->Con( 2 ); //illegal
    c->~Con(); // ok!
    delete c;
}

```

Thanks,

Answer: 
You can actually call it, it is just that the syntax is not that of calling a member method (of which the destructor is an special case), so it is not done with the *member access* operators. Rather you have to resort to the *placement-new* syntax:

```
Con c;
c.~Con();        // destroy, now c is not a Con anymore
new (&c) Con();  // recreate, now c is a Con again

```

As a particular case, in the C++0x proposal, that is actually used in one of the code examples, providing means to reuse a `union` as a different type in the event of an union containing non-POD elements:

```
union U {
   int i;
   float f;
   std::string s;
};

int main() {
   U u;
   new (&u.s) std::string( "foo" );
   u.s.~string();
   u.i = 5;
}

```

}
Ofc you can call it from an object instance , see this code :

```
 #include <iostream>
class foo{
      public :
      int foo_var;
      foo(){
            std::cout<<"foo_var = "<<foo_var<<std::endl;
            }
      };
int main()
{
    foo * f = new foo();
    // set foo_var
    f->foo_var = 10;
    // call constructor by passing object instanse
    foo * f1 = new(f) foo;
    std::cout<<(f==f1)<<std::endl;
    system("pause");
    return 0;
}

```

the second output is "foo\_var = 10" so it is working . the third output is "true" then (f==f1) that mean the constructor does not allocate new memory (the operator new does , but we passed a pointer to it so he wont alloc an other) 
there you are a really usefull practice : 

```
#include <iostream>
template <class t>
class smart_pointer{
      t * p; // the real normal pointer
      public :
      smart_pointer()
      {
          p = (t*) malloc(sizeof(t)); // allocate memory 
          try{ 
          new (p) t; // call the constructor 
          } catch (...)  // if it throws any exception
          {
                  free(p); // free p , dont use delete , because it will
                  // call the destroctor calling the destructor will cause 
                  // freeing a not allocated memory that causes a crash
                  throw; // throw the exception what ever it was
          }

      }
      ~smart_pointer(){delete p;}
      t operator = (t val) // assigment operator
      {
               *p = val;
               return val;
      }
      operator t(){ // type casting operator , usually for std::cout
               return *p;
               }
      };
int main()
{
    smart_pointer<int> x;
    x = 10;
    std::cout<<x<<std::endl;
    system("pause");
    return 0;
}

```

it is recommended to read "effective c++" , "more effective c++" , "effective modern c++" books