Lambda函数未在Visual Studio 2010中编译
Lambda Function does not compile in Visual Studio 2010
比起修复代码,我更感兴趣的是了解它为什么不编译。
致命错误C1001:编译器中发生内部错误。
int main()
{
class MyClass
{
public:
MyClass(const std::string & name)
: name_(name) {}
std::string name_;
};
auto creator = []() -> MyClass *
{
return new MyClass("Hello World");
};
MyClass * pMyClass = creator();
return 0;
}
致命错误C1001:编译器中发生内部错误。
每当您看到内部编译器错误时,您看到的都是编译器本身的错误。基本上,编译器没有给出编译器错误;它崩溃。
在这些情况下,就发生的时间而言,没有"为什么"(除非资源耗尽)。或者至少,不是一个容易确定的。最好的办法是尝试重新排列代码以使编译器正常工作。
如果您没有使用VC2010 SP1,请升级到service pack,然后重试。
作为另一个数据点,VS 2010编译器的64位版本没有崩溃,但它给出了以下错误:
test.cpp(16) : error C2061: syntax error : identifier 'MyClass'
如果将class MyClass
定义移到main()
之外,则x86和x64编译器都可以工作。
显然,x86编译器崩溃是一个错误。我认为在lambda中使用本地MyClass
类型应该很好(带有-std=gnu++0x
的GCC 4.6.1对此没有问题),所以我认为x64编译器抛出的错误也是一个错误。
我目前无法访问VS 11开发人员预览版来测试问题是否仍然存在
VS 11开发人员预览版(cl.exe版本17.00.40825.2)对lambda中使用的本地MyClass
类型没有问题。
相关文章:
- MSVC 2010 编译应用程序和 MSVC 2019 编译应用程序之间的行为差异
- 使用boost库在Visual Studio 2010中编译完整的静态可执行文件
- 编译错误C3861 Visual Studio 2010
- 无法在VS 2010中编译VCG库
- 在 MSVC 2010 中编译 64 位应用程序
- 使用 mkoctfile 与 Octave 和 Visual Studio 2010 编译器编译 .mex 或 .oct
- 我正在尝试在Visual Studio 2010上编译C ++代码,但出现链接器错误
- Visual Studio 2010 与 2012 编译时性能和稳定性比较,适用于C++用户
- 旧版 MFC 代码 (2005) 无法在 VC 2010 上编译
- C++程序是在VC++2010中编译的,而不是在Visual C++6.0中编译的
- Pinvoke与GCC在VB.net 2010中编译的c++dll有关
- 在LNK2038中编译Visual Studio 2010到2012 RC的MFC应用程序
- C++2010 Express Protobuf编译错误
- Visual Studio 2010在编译C++/CLI项目时出现奇怪错误
- 在Visual Studio 2010中编译glox库项目时出现问题
- 在VS 2010中将CUDA代码编译为二进制文件C++
- clang 3.3 可以在 VS 2010 中使用命名空间编译代码
- 用visual studio 2010编译simpleini的问题
- 如何使Visual Studio c++ 2010编译行为像gcc/g++?(或者相反)
- visual studio 2010 -编译单个文件,不需要IDE, c++