I have the following simplified scenario:
template< typename T>
struct A
{
A() : action_( [&]( const T& t) { })
{}
private:
boost::function< void( const T& )> action_;
};
When compiling with Visual C++ 2010, it gives me a syntax error at construction of action_:
1>test.cpp(16): error C2059: syntax error : ')'
1> test.cpp(23) : see reference to class template instantiation A<T>' being compiled
What is strange is that the same example, with no template parameter, compiles just fine:
struct A
{
A() : action_( [&]( const int& t) { })
{}
private:
boost::function< void( const int& )> action_;
};
I know that one workaround to the problem is to move the action_ initialization in the constructor body, instead of initialization list, like in the code below:
template< typename T>
struct A
{
A()
{
action_ = [&]( const T& t) { };
}
private:
boost::function< void( const T& )> action_;
};
... but I want to avoid such workaround.
Did anybody encountered such situation? Is any explanation/solution to this so called syntax error?
Broken implementation of lambdas in Visual C++ 2010? That's my best guess for an explanation.
Although, I'm intrigued what capturing scope variables by reference does in this situtation... Nothing?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With