Declare class object with parameters without using if...else
<p>I am new in C++ and try to write a cache simulator. The constructor of class CACHE is </p>

<pre><code>CACHE (int, int, int, int, CACHE *);   //declare
</code></pre>

<p>and in the <code>main()</code>, I am trying to create objects according to some variable:</p>

<pre><code>int main()
{
       if ( L2_size == 0 )      //only one level of cache   
       {
        CACHE L1(L1_size, blocksize, L1_assoc, inclusion, 0);
       }
       else                     //2 level of caches
       {
        CACHE L2(L2_size, blocksize, L2_assoc, inclusion, 0);
        CACHE L1(L1_size, blocksize, L1_assoc, inclusion, &amp;L2);
       }
}
</code></pre>

<p>The issue with this is that I am not able to access L1 and L2 since their scope are inside if...else.</p>

<p>Besides, I've tried using ? : operator to implement this, still get error:</p>

<p>no match for ternary operator.</p>

<p>Is there any way to do this? Thanks!</p>
