For example:
class Example
{
public:
explicit Example(int n) : num(n) {}
void addAndPrint(vector& v) const
{
for_each(v.begin(
Standard says the following (5.1.2):
The identifiers in a capture-list are looked up using the usual rules for unqualified name lookup (3.4.1); each such lookup shall find a variable with automatic storage duration declared in the reaching scope of the local lambda expression.
To my understanding GCC compiler is right because 'num' is in the reaching scope at the point of lambda declaration.