#include <iostream>
using namespace std;
 
#define HERAKLIT_TASK 1
 
class HeapOnly {
  public:
    HeapOnly() {} 
    void destroy() const { delete this; }
  protected:
    ~HeapOnly() {}
};
//HeapOnly h1;     // Destructor is protected so h1 can't be created globally
//HeapOnly func()  // Compiler error because destructor of temporary is protected
//{
 // HeapOnly *hoptr = new HeapOnly; // This is ok. No destructor is invoked automatically for heap-based objects
 // return   *hoptr;
//}
int main(void) {
#if HERAKLIT_TASK
  HeapOnly h2; // Destructor is protected so h2 can't be created on stack
#else
  HeapOnly * hptr = new HeapOnly();
  delete hptr;
#endif
  return 0;
}