c++ segmentation fault switch statement cin : <p>I have this code here </p>

<pre><code>string shapename;
bool warpspace;
const int size = 100;
 ShapeTwoD shape2D[size]; // ShapeTwoD is a parent class
int number =0;
static int count = 0;

while(choice !=999) 
{ 

    switch(choice)
    {
        case 1: 
        {
            cout&lt;&lt;"[Input sensor data]"&lt;&lt;endl;
            cout&lt;&lt;"Please enter name of Shape:";
            cin&gt;&gt;shapename;
            shape2D[size].setName(shapename); //segmentation fault
            cout&lt;&lt;"Please enter special type:";
            cin&gt;&gt;warpspace;
            shape2D[size].setContainsWarpSpace(warpspace);
            cin.clear();
            cin.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n');
            if(shapename == "Square" || shapename == "square")
                { square.setSquareCord(); count++; }
            if(shapename == "Rectangle" || shapename == "rectangle")
                { rect.setRectangleCord(); count++; }
            mainmenu();
            cin&gt;&gt;number;
            option(number);
        }break;//there are still multiple cases 
    }
}
</code></pre>

<p>when i try to compile and run it , it gives me segmentation error right after i enter the Shape <code>please enter name of shape :</code>  what have i done wrong here? </p>
