微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c++新特性-收缩转换,二进制,constexpr,以及namespace&&inline

char(112312312);//不会检查是否超过范围,会截断

char{12345435345};//会报异常,异常如下:

error C2397: 从“__int64”转换到“char”需要收缩转换
 warning C4305: “初始化”: 从“__int64”到“char”截断
warning C4309: “初始化”: 截断常量值

 

c++14二进制支持(0b) 即int a=0b1001;//9,0B1101(13)

constexpr标志返回值或其他表达式是常量,用于返回常量可以用于需要常量表达式的等数组中

constexpr int get()

{

  return 100;

}

int a[10+get()];//可以

inline 在命名空间新特性:namespace&& inline

#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <numeric>
#include <array>
#include <cstring>
#include <cstdio>
using namespace  std;
namespace all{
    namespace V2017
    {
        void fun(int num){ cout << "int V2017" << endl; }

    }
}
namespace all {
    //展开在all,调用
    inline namespace V2018
    {
        void fun(int num){ cout << "int V2018" << endl; }
        void fun(double num){ cout << "double V2018" << endl; }

    }
}
int main()
{
    all::V2017::fun(12);//明确调用
    all::V2018::fun(16);
    all:fun(1);//调用
    system("pause");

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐