Callback in Schleife



  • Hi,

    ich habe in meinen Projekt bestimmt 10 mal die selbe For-Schleife, wo sich jeweils nur der Inhalt unterscheidet.

    z.B. die hier

    for(int y = 0; y < CONST__anzY; y++)
       {
         for(int x = 0; x < CONST__anzX; x++)
         {
           model->getFeld(x,y)->OnClick = onClick;
         }
       }
    

    Wäre es möglich, dass ich eine Funktion schreibe, die die For-Schleife ausführt und dann im Inhalt statt einer konstanten Aktion eine art Callback (Lamda) ausführt?

    Wenn ja, wie heißt sowas in C++?

    Theoretiker



  • Ich meine das etwa so

    function mach_in_schleife(function aktion)
    {
      for(int y = 0; y < CONST__anzY; y++)
       {
         for(int x = 0; x < CONST__anzX; x++)
         {
           aktion(x,y);
         }
       } 
    }
    


  • Hallo

    Ja, die technische Grundlage nennt sich Funktionspointer.

    bis bald
    akari


Anmelden zum Antworten