Modify constructor parameter values before calling base class constructor
<p>I have following class hierarchy:</p>

<pre><code>class Base { // This class cannot be modified
public:
  Base(int a, int b, int c) {
     if ( a == 100 &amp;&amp; b == 200 &amp;&amp; c &lt; 100  ) // whatever condition
       throw "Error!";
  }
};

class Derived : public Base { // this class can be modified
public:
   Derived(int a, int b, int c) : Base(a, b, c) {}
};
</code></pre>

<p>class Derived is used in many places in code, so it cannot be replaced with some kind of factory function.</p>

<p>now the question is if there is some construct that would allow me to fix a,b,c values before calling Base constructor?</p>

<p>I know I can use functions like:</p>

<pre><code>   Derived(int a, int b, int c) : Base(FixA(a), FixB(b), FixC(c)) {}

   int FixA(int a) { /*fix a value*/ return a; }
   int FixB(int b) { /*fix b value*/ return b; }
   int FixC(int c) { /*fix c value*/ return c; }
</code></pre>

<p>but it wont allow me to set correct values in case when a b c values are dependent like in above Base class c-tor example.</p>

<p>I was thinking of extending this to:</p>

<pre><code>   Derived(int a, int b, int c) : Base(FixA(a,b,c), FixB(a,b,c), FixC(a,b,c)) {}

   int FixA(int a, int&amp; b, int&amp; c) { /*fix a b c values*/ return a; }
   int FixB(int&amp; a, int b, int&amp; c) { /*fix a b c values*/ return b; }
   int FixC(int&amp; a, int&amp; b, int c) { /*fix a b c values*/ return c; }
</code></pre>

<p>I suppose there should also be some kind of flag indicating that fix was already done. I am not sure if this is actually correct c++.</p>

<p>I know the best solution is to actually catch exception.</p>
