Problem using lambda function with std::for_each

Hi!
I had tried to use a std::for_each for iterate through list elements. The problem is that I do not get it to work.

The code:

1
2
3
4
5
6
7
8
9
10
11
12
void GameScreen::Draw(void)
{
    std::for_each(
                  components.begin(),
                  components.end(),
                  [](Component cpt) // Error here.
                  {
                      if(cpt.IsVisible)
                        cpt.Draw();
                  }
                  );
}


The error:

error: expected primary-expression before '[' token
error: expected primary-expression before ']' token
error: expected primary-expression before 'cpt'

¿Any idea?
It looks like that your compiler does not support lambda expressions.
Topic archived. No new replies allowed.