–Example Updated–
Here’s a bit of code :
int retInt(int a) { return a; }
void randomFunction()
{
int a = 3;
auto future = async([&]{ return retInt(a); });
const auto ret = future.get();
}
VS2012 intellisense tells me that ‘ret’ is a const < error-type > and will not let me compile, giving me an output message of:
[cannot deduce type for ‘const auto’ from ‘void’]
If for example I change ‘ret’ from const auto to const int and specify an actual type everything compiles just fine, but I’m wondering why the auto version doesn’t work and if there would be a possible code change of some sort to make a version with auto compile.
Any ideas?
Note:
Changing the
auto future = async([&]{ return retInt(a); });
to
auto future = async([&] ()->int{ return retInt(a); });
yields the same result
You have extra
[]inside lambda expression, which makes an embedded lambda express. inner lambda returns1but outter lamda return type is not specified which is default to void.change
to:
Edit:
Your new code just works fine on VS2012 NOV CTP and gcc 4.7.2.
Note:
you are capturing local variable a by reference, it’s safe for async thread, you may want to capture it by value.
Sample code compiled:
http://liveworkspace.org/code/X66xE$2