title: Alternative to conditional compilation in c++, using multiple .cpp files
body: <p>Suppose I have a C++ class that uses conditional compilation:</p>
  
  <p>C.hpp</p>
  
  <pre><code>namespace NS{
    class C {
      public:
        C(void);
        ~C(void);
        int func( int arg1 );
      private:
        int memberVar;
  }
  </code></pre>
  
  <p>C.cpp:</p>
  
  <pre><code>#include "C.hpp"
  
  namespace NS{
    C::C( void ){ memberVar = 0; }
    C::~C( void ) {}
    int C::func( int arg1 ){
      int retval = 0;
      memberVar = arg1;
  #ifdef DEV_BUILD
      retval = memberVar;
      printf( "memberVar was set.\n" );
  #endif
      return retval;
    }
  }
  </code></pre>
  
  <p>(this is a simplified example; imagine that the class <code>C</code> is several hundred lines long, with some of its functions using conditional compilation, each using the same condition: #ifdef DEV_BUILD.  The application is an embedded-systems application, and the condition is used to distinguish between test hardware and production hardware, which have some differences)</p>
  
  <p>I've been advised to instead implement the funcs in separate .cpp files... but I'm sort of hung up as to what the best way is.</p>
  
  <p>My first impulse was to create C_dev.cpp and C_prod.cpp, implement <code>C::func()</code> differently in each, and edit C.cpp thusly:</p>
  
  <pre><code>#include "C.hpp"
  #ifdef DEV_BUILD
  #include "C_dev.cpp"
  #else
  #include "C_prod.cpp"
  #endif
  
  namespace NS{
    C::C( void ){ memberVar = 0; }
    C::~C( void ) {}
  }
  </code></pre>
  
  <p>...but is this bad style?  Or otherwise problematic?</p>
  
  <p>Additional restrictions:</p>
  
  <ul>
  <li>Can't use subclasses.</li>
  <li>Can't use template classes.</li>
  </ul>
  
  <p><em>(Update: Using separate files was suggested, but not required.  I'm open to other suggestions)</em></p>