Feb 052013

Write a class, such that user can create its object on heap (using new) but user should not be able to create its object on stack or data area. i.e if the class is MyClass, then

MyClass stackObj;     // Should give compile time error.
MyClass *heapobj = new MyClass;      // This should be OK, & allowed.

Give the definition of class, MyClass (How should you change the scope or anything else of constructor / destructor / assignment operator or any other function, etc.). Continue reading »