Can we declare a object inside the if-else statement? : <p>This code is the main function for  the implementation of queues using arrays also using template class.   </p>

<pre><code>int main(){
    int choice, n;

    cout&lt;&lt;"Enter 1 for integer 2 for double\n";
    cin &gt;&gt; choice;
    cout&lt;&lt;"Enter the size of queue\n";
    cin&gt;&gt;n;

    if (choice == 1)
        queue&lt;int&gt; obj(n);
    else
      queue&lt;double&gt; obj(n);

    for(;;){
        cout&lt;&lt;"1:Insertrear 2:Deletefront 3:Display 4:Exit\n";
        cin &gt;&gt; choice;

        switch(choice){
            case 1:obj.insertRear();break;
            case 2:obj.deleteFront(); break;
            case 3:obj.display();break;
            default: return 0;
        }
    }

    return 0;
}
</code></pre>

<p>The thing that I could not understand is, why I got error <code>'obj' was not declared in this scope</code> in the line below the <code>switch</code> statement.</p>

<p>Any help will be well appreciated.</p>
