Tôi đã thử nghiệm một số tính năng C++ 0x mới với G ++. Lambdas, auto
và các tính năng mới khác hoạt động như một nét duyên dáng, nhưng vòng lặp for-loop không thể biên dịch được. Đây là chương trình tôi đã thử nghiệm:G ++ không biên dịch C++ 0x dựa trên phạm vi cho vòng lặp
#include <iostream>
#include <vector>
int main()
{
std::vector<int> data = { 1, 2, 3, 4 };
for (int datum : data)
{
std::cout << datum << std::endl;
}
}
tôi biên dịch nó với:
g++ test.cpp -std=c++0x
Tôi cũng đã cố gắng gnu++0x
, nhưng sản lượng là như nhau.
Đây là kết quả:
test.cpp: In function ‘int main()’:
test.cpp:8:21: error: expected initializer before ‘:’ token
test.cpp:12:1: error: expected primary-expression before ‘}’ token
test.cpp:12:1: error: expected ‘;’ before ‘}’ token
test.cpp:12:1: error: expected primary-expression before ‘}’ token
test.cpp:12:1: error: expected ‘)’ before ‘}’ token
test.cpp:12:1: error: expected primary-expression before ‘}’ token
test.cpp:12:1: error: expected ‘;’ before ‘}’ token
Cảm ơn trước sự giúp đỡ của bạn.
EDIT: Tôi đang sử dụng phiên bản GCC 4.5.2, hiện tôi thấy quá cũ.
Phiên bản gcc bạn đang sử dụng? – pmr