C++ c++;分段故障切换语句
我这里有这个密码C++ c++;分段故障切换语句,c++,inheritance,segmentation-fault,switch-statement,C++,Inheritance,Segmentation Fault,Switch Statement,我这里有这个密码 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: { c
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<<"[Input sensor data]"<<endl;
cout<<"Please enter name of Shape:";
cin>>shapename;
shape2D[size].setName(shapename); //segmentation fault
cout<<"Please enter special type:";
cin>>warpspace;
shape2D[size].setContainsWarpSpace(warpspace);
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
if(shapename == "Square" || shapename == "square")
{ square.setSquareCord(); count++; }
if(shapename == "Rectangle" || shapename == "rectangle")
{ rect.setRectangleCord(); count++; }
mainmenu();
cin>>number;
option(number);
}break;//there are still multiple cases
}
}
字符串shapename;
布尔空间;
常数int size=100;
ShapeWood shape2D[尺寸];//ShapeWod是一个父类
整数=0;
静态整数计数=0;
while(选项!=999)
{
开关(选择)
{
案例1:
{
cout您正在访问阵列边界的外侧:
shape2D[size].
^^^^
有效数组索引从0到大小-1解决此类问题的正确工具是调试器。在询问堆栈溢出问题之前,您应该逐行检查代码。有关更多帮助,请阅读。至少,您应该[编辑]您的问题包括一个重现您的问题的示例,以及您在调试器中所做的观察。