Anonymous Functions In C++

Hi!

I have a program that runs multiple apps. To do this, I switch out what loop function I'm running using an array of function references, as seen here:

void loopA(void){
  //do some stuff
}
void loopB(void){
  //do some other stuff
}
const void (*appLoops[2])()={&loopA,&loopB};

However, for very short functions, this is very impractical and uses a lot of space.

I'm wondering if you can do anonymous function declarations and store them directly during the array's initialization.

//This code is javascript, but is what I hope to achieve in C++:

var appLoops=[
  function(){/*do some stuff*/},
  function(){/*do some other stuff*/}
];

This may be impossible, but it sure would be handy if it were!
So is it?

Thanks!

Check out function pointers.

Check out C++ lambda expressions

@keithRB...That's what I'm doing?

Fuzzyzilla:
I have a program that runs multiple apps. To do this, I switch out what loop function I'm running using an array of function references, as seen here:

void loopA(void){

//do some stuff
}
void loopB(void){
 //do some other stuff
}
const void (*appLoops[2])()={&loopA,&loopB};

@AWOL Thanks. I'll look into it.
All I need to do is take 0 arguments, do some simple operations, and return a String.

Okay, I think I've got lambdas down. But...

But how do you create an array of them?

Are they called like normal functions?