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, this gives me a syntax error when building the _ action:
1>test.cpp(16): error C2059: syntax error : ')'
1> test.cpp(23) : see reference to class template instantiation A<T>' being compiled
It is strange that in the same example, without a template parameter, it compiles just fine:
struct A
{
A() : action_( [&]( const int& t) { })
{}
private:
boost::function< void( const int& )> action_;
};
I know that one way to solve this problem is to move the initialization action_ to the constructor body instead of the initialization list, as 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 this workaround.
Has anyone encountered such a situation? Is there any explanation / solution for this so-called syntax error?
source
share