Căt*_*tiș 5 c++ lambda visual-c++-2010 c++11
我有以下简化方案:
template< typename T>
struct A
{
A() : action_( [&]( const T& t) { })
{}
private:
boost::function< void( const T& )> action_;
};
Run Code Online (Sandbox Code Playgroud)
使用Visual C++ 2010进行编译时,它在构造action_时给出了语法错误:
1>test.cpp(16): error C2059: syntax error : ')'
1> test.cpp(23) : see reference to class template instantiation A<T>' being compiled
Run Code Online (Sandbox Code Playgroud)
奇怪的是,同样的例子,没有模板参数,编译得很好:
struct A
{
A() : action_( [&]( const int& t) { })
{}
private:
boost::function< void( const int& )> action_;
};
Run Code Online (Sandbox Code Playgroud)
我知道问题的一个解决方法是在构造函数体中移动action_初始化,而不是初始化列表,如下面的代码中所示:
template< typename T>
struct A
{
A()
{
action_ = [&]( const T& t) { };
}
private:
boost::function< void( const T& )> action_;
};
Run Code Online (Sandbox Code Playgroud)
......但我想避免这种解决方法.
有人遇到过这种情况吗?是否有任何解释/解决这种所谓的语法错误?
| 归档时间: |
|
| 查看次数: |
418 次 |
| 最近记录: |