c++ - 带有 unique_ptr 参数回归的 Visual Studio 2012 lambda?

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

我惊讶地发现在 Visual Studio 2012 Update 1 中以下内容不再编译:

[](unique_ptr<int>){};

编译器错误表明它无法访问 unique_ptr 的私有(private)复制构造函数。 以上在 Visual Studio 2010 中运行良好。

它在 gcc 4.7.2 中也编译得很好

这是一个已知的错误,还是这实际上是预期的行为?我在 Microsoft Connect 上找不到任何内容。

编辑:我刚刚更新到 Visual Studio 2012 Update 2,问题仍然存在。

EDIT2:我已经提交了 bug report on Microsoft Connect ,如果对你也有影响,欢迎点赞。

最佳答案

试试这个:

int a;
[a](unique_ptr<int>){};

不管它是什么,只要明确捕获一些东西即可。

关于c++ - 带有 unique_ptr 参数回归的 Visual Studio 2012 lambda?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16135795/

相关文章:

c++ - 在 C++17 中初始化整数 vector 的 vector

visual-studio-2010 - 使用 Visual Studio 的调试器查看动态分配的空终止字符串

c++ - gcc 深/双/嵌套类型转换

c++ - 前向声明类型上的 std::vector

c++ - 创建嵌套类的实例

C++20 #import ""- 语句 : Will it be possible to use multiple preprocessed header files

c++ - 为什么非多态 typeid 需要 RTTI?

c++ 模板和析构函数问题

c++ - 对重载函数错误的奇怪模棱两可的调用

c++ - 可以为晋升制定类型特征吗?