开关/案例 - 预期会员名称或“;”在声明说明符之后

时间:2014-04-01 10:40:07

标签: c++

"预期会员名称或";"在声明说明符之后"顶行开关(东西)上出现错误

 float waveform = getParameter(6);

switch(waveform){
    case 1: Sine signalGenerator
        break;
    case 2: SawWave signalGenerator
        break;
    case 3: SquareWave signalGenerator
        break;
    default: Sine signalGenerator
}

有关如何对其进行排序的任何建议都会很棒!提前谢谢!

这是真正的代码:

float waveform = getParameter(6); 
switch(waveform)
{ case 1: Sine signalGenerator break; 
  case 2: SawWave signalGenerator break; 
  case 3: SquareWave signalGenerator break; 
  default: Sine signalGenerator 
} 

1 个答案:

答案 0 :(得分:2)

你想要的可能就是:

int waveform = (int) getParameter(6);
WaveBase* sigGen;
switch(waveform) {
    case 1:  sigGen = new Sine; break; 
    case 2:  sigGen = new SawWave; break;
    case 3:  sigGen = new SquareWave; break; 
    default: sigGen = new Sine;
}

// use  sigGen here

delete sigGen;

这假设Sine,SawWave和SquareWave有一个共同的基础(他们应该)
并且它的析构函数是虚拟的(它应该)