c++ - Visual 2010 中带有 lambda 函数和枚举的 C2665,是错误还是正常?

标签 c++ visual-studio-2010 visual-c++ lambda c++11

我可以编译以下代码:

enum E {a, b, c};
void f()
{
    E e;
    std::function<void()> f = [&]() { e = a; };
} 

但不是下面的:

void f()
{
    enum E {a, b, c};
    E e;
    std::function<void()> f = [&]() { e = a; };
} 

发出以下编译器错误:

1>test.cpp(5): error C2665: '`anonymous-namespace'::<lambda1>::<lambda1>' : none of the 2 overloads could convert all the argument types
1>          test.cpp(5): could be '`anonymous-namespace'::<lambda1>::(f::E &,f::E &)'
1>          while trying to match the argument list '(f::E, f::E)'

这个错误是可以预料的还是一个错误?

最佳答案

这似乎与 http://social.msdn.microsoft.com/Forums/en/vclanguage/thread/88f533d8-b7f5-4416-bdcf-b461aeb74178 中的问题相同.在那里,它似乎是编译器中的错误。 MSVC 似乎对 lambda 中的本地类型存在一些问题;另见 http://connect.microsoft.com/VisualStudio/feedback/details/675113/lambda-expression-causes-internal-compiler-error#details .

5.1.2 Lambda 表达式 [expr.prim.lambda] 中没有任何语言表明不能在 lambda 中捕获本地定义的类型。

关于c++ - Visual 2010 中带有 lambda 函数和枚举的 C2665,是错误还是正常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12177230/

相关文章:

c++ - dllexport意外不会在引用项目时导致链接器错误

c++ - 如果位于头文件中的 "heavy"函数没有标记为 'inline' ,那么它的代码被编译到哪里?

visual-studio - 代码覆盖率 Visual Studio 2010

c++ - 立方体 OPENGL 上缺少面

c# - 是否可以在不转换的情况下使用 Visual Studio 2010 编辑 Visual Studio 2008 解决方案?

c# - visual studio 退出调试没有任何异常或错误

c++ win32编辑框光标不闪烁

c++ - 将 noexcept 与 constexpr 函数一起使用

C++ 结构成员,什么类型可以在 iPhone 上保留日历时间?

C++ 结构和构造函数