lambda in static member function

1
2
3
4
5
6
7
8
9
10
struct A {
	static void fn2() {
	}
	static void fn1() {
		auto x = [&]() {
			A::fn2();
		};
		x();
	}
};

the code doesn't compile in VS2010, why?

Thanks.
Last edited on
it compiles with GCC 4.7
> auto x = [&] () { A::fn2() ; }

Just making a wild guess: the Microsoft compiler is getting confused because of the attempt to capture by reference when there is nothing to capture. It annotates A::fn2() as this->A::fn2() (with a captured this).

Try: auto x = [] () { A::fn2() ; }
Thanks, seems a bug of MS compiler

1
2
3
4
5
6
7
8
9
10
11
12
13
struct A {
	static void some_unique_name() {//have to use this to get around
		A::move();
	}
	static void move() {// conflict with std::tr1::move
	}
	static void fn1() {
		auto x = [&]() {
			some_unique_name();
		};
		x();
	}
};
Last edited on
Topic archived. No new replies allowed.