C++ how to increment objects name in a loop ?

Status
Not open for further replies.

emmanuel63

Well-known member
Hello,

I am not a C++ expert... and I don't know how to compact this kind of code in a loop :
Code:
  }
  pot0.update(output[0]);
  pot1.update(output[1]);
  pot2.update(output[2]);
  pot3.update(output[3]);
  pot4.update(output[4]);
  pot5.update(output[5]);
  pot6.update(output[6]);
  pot7.update(output[7]);
  pot8.update(output[8]);
  pot9.update(output[9]);
  pot10.update(output[10]);
  pot11.update(output[11]);
  pot12.update(output[12]);
  pot13.update(output[13]);
  pot14.update(output[14]);
  pot15.update(output[15]);
}

It's easy to increment output using " for (int i = 0;i<16;i++) " , but do you increment pot"i".udpdate() objects ?
I guess you make an array of objects and then use pointers, but I am lost.

Emmanuel
 
This should work
Code:
pot pots[16];

void update()
{
    for (int i = 0; i < 16; i++)
    {
        pots[i].update(output[i]);
    }
}
 
No pointers in that code, just an array of objects. If pointers were involved you'd replace '.' by '->'
(or is that what you've done?)
 
Status
Not open for further replies.
Back
Top