您的位置:首页 > 编程语言 > C语言/C++

【c++11并不遥远】使xcode工程支持c++11特性

2015-09-29 13:07 295 查看
一、操作步骤:

工程文件 => Build Settings(All) => Apple LLVM 6.1 Language - C++

C++ Language Dialect: C++11 [-std=c++11]

C++ Standard Library: libc++ (LLVM C++ standard library with C++11 support)

二、测试代码(可编译通过即可):

void whatValue(int&& val) {
printf("R-Value: %d\n", val);
}
void whatValue(const int& val) {
printf("L-Value: %d\n", val);
}
void testRValue(int&& i) {
whatValue(i);
whatValue(std::move(i)); // g++ 不支持 std::move<int>(i); 这种写法
}
constexpr int getCstExpr() {
return 888;
}
void testFor11() {
int arrInt[5] = {1, 2, 3, 4, 5};
for (int& item : arrInt) {
item *= 2;
}
}
void testTypeInference() {
int value[getCstExpr() + 123];
const std::vector<char> vec(1);
auto a = vec[0];
decltype(a)b; // g++ 不支持 decltype(vec[0])b; 这种写法
auto c = 0;
auto d = c;
decltype(c) e;
decltype((c)) f = e;
decltype(0) g;
}
参考连接:

cocos2d-x工程中,让xcode4.6能够使用C++11标准库

http://my.oschina.net/u/160089/blog/174692

测试编译器是否支持C++11新特性(1)

http://my.oschina.net/u/186539/blog/58074
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: