title: Passing Parameters to Base Class Constructors C++
body: <p>I like to keep my class declarations and definitions separate in C++. So, in a header I may define a 'base' class as follows:</p>
  
  <pre><code># Base.h
  class Base 
  {
      int n;    
  public:
      Base(int x);
  };
  </code></pre>
  
  <p>and define its constructor implementation in a cpp file, i.e.,</p>
  
  <pre><code># Base.c
  Base::Base(int x) 
  {
      n = x;
  }
  </code></pre>
  
  <p>Now, if I define a 'derived' class that inherits the 'base' class, I can pass parameters to the base class as follows:</p>
  
  <pre><code>#Derived.h
  class Derived : public Base
  {
      int t;
  public:
      Derived(int y) : Base(t) {t = y;}
  }
  </code></pre>
  
  <p>But doing it this way requires that I place the body of the constructor for the Derived class in the header file, i.e., <code>{t = y;}</code>, and thus the constructor definition is no longer separate from its declaration. Is there a way to pass arguments to a class's base class constructor that still enables me to define the constructor for the derived class in a cpp file?</p>