title: Interfaces, hiding concrete implementation details in C++
body: <p>I have a question regarding hidinging interface details in C++ libraries. The problem is ilustrated with the following example:</p>
  
  <p>Let's say w have a class called <strong><em>ISystem</em></strong> which exposes methods like <em>Init, Run, Tick, Shutdown, GetXXXSubSystem.</em>
  Where X are pointers various interfaces like: <em>ISoundSystem, IInputSystem</em></p>
  
  <p>We also have concrete implementations of ISystem like:
  <strong><em>Win32System, OSXSystem</em></strong> etc.</p>
  
  <p>These specific implementations use a pimpl idiom to hide internals
  and for example Win32System instantiates <strong>Win32RawInputSystem</strong>
  as input system manager.</p>
  
  <p>All such managers do have their own <em>Init, Run, Tick and Shutdown</em> methods
  which are not part of the interface (only concrete implementation) and these are run and managed by the concrete system implementation.</p>
  
  <p>The user calling GetXXXSubSystem gets interface pointer without those methods (Init etc..) but
  still he could cast the pointer he gets to concrete implementation
  and trigger methods like Init Run Tick etc. which he shouldn't have access to.</p>
  
  <p>The question is, is it possible to hide the concrete class somehow? I tried to make those methods
  protected in the concrete implementations and template the class on type which would eventually be friend but this appears to be prohobited and existing hacks do not work with VC11.</p>
  
  <p>The only way I can think of right know is to transfer the concrete implementation declaration from header
  into the cpp file of Win32System class but I see  ahuge drawback of doing this (even not sure if this would work), because this way each subsystem
  would have to be also part of this cpp file and it would become a maintainability nightmare.</p>
  
  <p>Another solution I am thinking about is using factory method like</p>
  
  <pre><code>(RawInput.h) 
  IInputSystem* CreateRawInputSystem();
  
  (RawInput.cpp)
  class RawInput : public IInputSystem {}; ...
  </code></pre>
  
  <p>and move definition of the class to cpp file but then, how I would acces this type from other parts of my library (ie in Win32System impl)?</p>
  
  <p>Is it possible to include .cpp files form other .cpp files?</p>
  
  <p>Thanks in advance for any tips.</p>