如何在Visual Studio 2010 Express版上启用C++11编译器?

6

我正在使用tbb::parallel_for函数,它使用lambda表达式。以下代码出现语法错误:

void parallel_relax( Class object, std::vector<Vertex *> verList ) {
    tbb::parallel_for (blocked_range<int>(0, verList.size()), [=](const blocked_range<Vertex *>& r) {
        for(Vertex *vit = r.begin(); vit != r.end(); ++vit) {
            Vertex *v = vit;
            object.function(v);
        }
    });
}

语法错误:

syntax error : '['
1>main.cpp(16): error C2143: syntax error : missing ')' before '{'
1>main.cpp(16): error C2143: syntax error : missing ';' before '{'
1>main.cpp(17): error C2065: 'r' : undeclared identifier
1>main.cpp(17): error C2228: left of '.begin' must have class/struct/union
1>          type is ''unknown-type''
1>main.cpp(17): error C2065: 'r' : undeclared identifier
1>main.cpp(17): error C2228: left of '.end' must have class/struct/union
1>          type is ''unknown-type''
1>main.cpp(20): error C2059: syntax error : ')'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我认为这是编译器的问题。我该如何在Visual Studio 2010 Express版中获取C++11编译器呢?请给予建议。


第16和17行是什么? - Nicol Bolas
"tbb::parallel_for" 在第16行,"for(Vertex *vit = r.begin(); vit != r.end(); ++vit)" 在第17行。 - Sumanth
那我不能使用C++11,因为我在Windows 7上只能使用Visual Studio 2010?顺便说一句...我不想使用带MinGW G++的Eclipse,因为我觉得它很丑... :( - ha9u63a7
2个回答

4

如何启用C++11特性?如果它默认已启用,为什么会出现语法错误? - Sumanth
2
正如我之前所说,并非全部都支持。一开始看起来列表有点误导人,但是往下看你会发现VC10对于lambda的支持只是部分的,这就是为什么你会得到语法错误的原因。 - Chris
这个链接似乎只列出了VS2012、13、15。 - slyy2048

3
为了使用C++11功能,您应该使用最新版本的Visual Studio 2012
C++11 Features (Modern C++)中得知:
Visual C++ 2010实现了C++0x核心语言规范中的许多功能,这是C++11的前身,Visual Studio 2012中的Visual C++扩展了许多C++11功能。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接