Saturday, July 12, 2008

C++ Challenge of the Month: July 2008

Starting this month, I would be posting a C++ programming problem, and it's solution every month in a series called C++ Challenge of the Month (CCOM). The solution will be posted a couple of weeks after the problem and in the meanwhile, I hope to see a few readers try their hand at the problem. So here we go.


CCOM #1: Write the outline of a smart pointer class capable of managing pointers to classes from hierarchies which don't have a virtual destructor

Need a smart pointer, which can be used like:

smart_ptr<base> p = new derived;

When p goes out of scope, the object must be deleted and the destructor of derived must be called, irrespective of whether ~base() is virtual or not.

Courtesy, Syam Krishnan, Thiruvananthapuram, Kerala.