在初始化浮点数组时,c++交叉初始化跳转到case标号

c++ cross initialization jump to case label when initializing a float array

本文关键字:初始化 case 标号 c++ 数组      更新时间:2023-10-16

我有3个类M, L, p,每个类都有自己的。header和。cpp用于封装实践,我在每个。header和。cpp中分别放置了相关的函数和属性

我有这个函数float L::calculate(arg,arg,arg,arg)这里是在L.cpp,它只是一个固定的公式,参数取自类本身。但是我有另一个类P

在p .cpp中,我得到了L类的计算函数的集合。在类P中,我也有构造函数,1默认和1接受参数(我也在两个构造函数中初始化L)

然后在我的类M中所有的实现集合在一起。

我正在尝试创建一个像这样的浮点数组:

float calculateThis[size]; // the size is fixed at 50.

然后在for循环中,x小于size

i did this:

calculateThis[x] = newL[x].caculate(args,args,args,args);
newP.setCalculate(calculateThis[x]);
++x;

我还声明了top

L newL[size]; //Used for some other methods that i have wrote to get inputs   and save it .
P newP[size];

当我编译时,我得到这个错误:

  crosses initialization of ‘float calculateThis[size]’
   float calculateThis[size];

基本上我试图保存计算函数,返回一个浮点数到一个浮点数组

编辑:

    switch(choice)
    {
    case 1: // 1st Choice.
    while(entry<size)
    {
      //getting user input and saving it by newL.set / newP.set     
    };
    break;
    case 2:
    float calculateThis[size]; // the size is fixed at 50.
  for(x=0,x<size)
  {       calculateThis[x] = newL[x].caculate(newL.get(),newL.get(),newL.get(),newL.get());
          newP.setCalculate(calculateThis[x]);
           ++x;
  }
    break;
    default:break;  
    }

使用括号表示这是calculateThis的局部作用域:

    case 2:
    {
      float calculateThis[size]; // the size is fixed at 50.
      for(x=0,x<size)
      {       
        calculateThis[x] = newL[x].caculate(newL.get(),newL.get(),newL.get(),newL.get());
          newP.setCalculate(calculateThis[x]);
           ++x;
      }
     }break;