0

I'm trying to compile C++11 list congregation initialization on clang++ on mac.

#include <iostream>
#include <list>
#include <string>

using namespace std;
int main(int argc, char *argv[]) {
    list<string> aList = {"abc", "def", "xyz"};
}

This is the command for the compilation.

clang++-mp-3.1 -std=c++11 iterator.cpp

I got no matching constructor error.

iterator.cpp:7:23: error: no matching constructor for initialization of
  'std::list<string>'
std::list<string> aList = {"abc", "def", "xyz"};
                  ^       ~~~~~~~~~~~~~~~~~~~~~

I tried with XCode

clang -v
Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix

I also tried with clang++ from port

clang++-mp-3.1 -v
clang version 3.1 (branches/release_31)
Target: x86_64-apple-darwin11.4.2
Thread model: posix

I got the same result. What might be wrong?

clang's support of C++ 11 lambda

4

1 回答 1

0

我试过icc,得到了同样的错误。我想问题出在模板而不是编译器上。icc 使用现有的模板 /usr/include/c++/4.2.1 并且实现不完全支持 c++11。

我从端口尝试了 gcc 4.8

sudo port install gcc48

它工作正常

/opt/local/bin/g++-mp-4.8 -std=c++11 Iterator.cpp 

Intel C++ Compiler 12.1.2如何开启C++0x

于 2013-06-02T00:03:19.393 回答