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

本文介绍了如何在Xcode工程中启用C++11支持,包括在Build Settings中设置C++ Language Dialect为C++11和选择libc++作为C++标准库。并提供了测试C++11特性的代码参考链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、操作步骤:

工程文件 => 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



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值