【问题标题】:How to enable C++11 compiler on visual studio 2010 express edition?如何在 Visual Studio 2010 Express Edition 上启用 C++11 编译器?
【发布时间】:2013-03-29 18:08:28
【问题描述】:

我正在使用 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 Edition 的 c++11 编译器。请提出建议。

【问题讨论】:

  • 第 16 行和第 17 行是什么?
  • "tbb::parallel_for" 是第 16 行,"for(Vertex *vit = r.begin(); vit != r.end(); ++vit)" 是第 17 行跨度>
  • 所以我不能使用 C++11,因为我在 Windows 7 上,我只能使用 Visual Studio 2010?顺便说一句...我不想将 Eclipse 与 MinGW G++ 一起使用,因为我觉得它很难看... :(

标签: c++ visual-studio-2010 visual-c++ c++11 tbb


【解决方案1】:

Visual C++ 2010 Express 确实包含 C++11 功能,但不是全部。以下是它支持的功能列表(以及 VC++ 2012): http://msdn.microsoft.com/en-ca/library/vstudio/hh567368.aspx

【讨论】:

  • 如何启用 C++11 功能?如果默认启用,为什么会出现语法错误?
  • 正如我上面所说,不是所有的。乍一看,该列表有点欺骗性,但再往下看,您会发现 VC10 中对 lambda 的支持只是部分的,这就是您收到语法错误的原因。
  • 这个链接好像只列出了VS2012,13,15
【解决方案2】:

要获得 C++11 功能,您应该使用最新版本 Visual Studio 2012

来自C++11 Features (Modern C++)

Visual C++ 2010 在 C++0x 核心语言规范(C++11 的前身)中实现了许多功能,Visual Studio 2012 中的 Visual C++ 在此基础上进行了扩展,包含了许多 C++11 功能。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多