title: Premature exit and destructors
body: <p>I'm writing a linux deamon in a class, which is a smart pointer of an App class:</p>
  <p>App.hpp</p>
  <pre><code>class App
  {
  public:
      App(void)
      {
          this-&gt;ptrDaemon = std::make_unique&lt;Daemon&gt;();
          this-&gt;ptrDaemon-&gt;ptrApp = this;
      }
      ~App(void) = default;
  
      // Members
  public:
      std::unique_ptr&lt;Daemon&gt; ptrDaemon = nullptr; // This is constructed in the constructor
  };
  </code></pre>
  <p>Daemon.hpp</p>
  <pre><code>class Daemon
  {
      ~Daemon() = default;
      App *ptrApp = nullptr; // This pointer is assigned to the app instance in the App constructor
      bool daemonise()
      {
          pid_t pid{};
  
          pid = fork();
  
          if (pid &lt; 0)
          {
             return false;
          }
          
          // Exit father 
          if (pid &gt; 0)
          {
             this-&gt;ptrApp-&gt;~App(); // This works, but is it a good practice?
             std::exit(EXIT_SUCCESS);
          }
          // More code
      }
  }
  </code></pre>
  <p>In this case, I need to exit the father process prematurely, so if I used <code>std::exit(0)</code> the smart pointer wouldn't be freed. To avoid that, I used the other objects destructor.</p>
  <p>Is it a good practice (looks ugly to me)? Is there any other solution I could use?</p>
  <p>Thanks in advance!</p>