C++ かんすうないかんすう ない

C++ には関数内関数がないらしい.
struct使えば,似非関数内関数は作れるが,
この似非関数内関数は親関数の変数に触ることができない.

例えば,以下のプログラムはコンパイルエラーになった.

// test.cpp
int main() {
  int c = 0;
  struct Func {
    void operator () () {
      c ++;
    }
  } f;
  f();
  return 0;
}

コンパイルすると,以下のようなメッセージが表示される.

% g++ -O2 -o a.out test.cpp 
test.cpp: In member function ‘void main()::Func::operator()()’:
test.cpp:5: error: use of ‘auto’ variable from containing function
test.cpp:2: error:   ‘int c’ declared here

#ラムダ式を使えばできるんですかね.

追記
以下のようにBoost.Lambdaを使用すれば可能だそうです.
http://codepad.org/WAU3yRgH