title: Cross-platform class with template function
body: <p>I currently have two different headers defining the same class. What changes between them is the functions implementation and a single variable.</p>
  
  <p><strong>header_linux.h</strong></p>
  
  <pre><code>class Class
  {
  private:
      QStringList processesList; // Same variable
      pid_t pid; // Different variable
  
  public:
      void fillProcessesList()
      {
              // Different implementation
      }
  
      void isProcessRunning(QString name)
      {
              // Same implementation
      }
  
      template&lt;typename T&gt;
      bool readMemory(unsigned long long address, T &amp;destination)
      {
              // Different implementation
      }
  </code></pre>
  
  <p><strong>header_win32.h</strong></p>
  
  <pre><code>class Class
  {
  private:
      QStringList processesList; // Same variable
      HANDLE handle; // Different variable
  
  public:
      void fillProcessesList()
      {
              // Different implementation
      }
  
      void isProcessRunning(QString name)
      {
              // Same implementation
      }
  
      template&lt;typename T&gt;
      bool readMemory(unsigned long long address, T &amp;destination)
      {
              // Different implementation
      }
  </code></pre>
  
  <p>I would like to have the common variables and functions in a single file.</p>
  
  <p>My idea was to create <strong>header.h</strong> which defines the class and its members, <strong>header.cpp</strong> which implements the common functions and then <strong>header_linux.cpp</strong> and <strong>header_win32.cpp</strong> which implement the OS-specific functions.</p>
  
  <p>However, template functions must be implemented in the header file.</p>
  
  <p>I could check the operating system using a preprocessor macro and according to that use the right implementation, in a single header, but the functions are many and their body is big.</p>
  
  <p>After a lot of research I found the PIMPL idiom, but the implementation seems complicated.</p>
  
  <p>Is there a better way?</p>