c++处理类型

//类型别名

typedef:

typedef int ity;

ity x(12);

typedef int* pity;

pity ip(&x);

cout << *ip << endl;

 

//using

using ud = double;

ud dval(3.1415);

using upd = double*;

upd pd(&dval);

cout << *pd << endl;

 

auto:能自动识别自动推理数据类型

auto i(0), *p(&i);

auto sz(0), pi(3.14);//错误 sz和pi类型不一致

auto会忽略顶层const,保留底层const

auto i(9);

const int ci(i), &cr(ci);

auto b = ci;//b是一个整数(ci的顶层特性被忽略)

 

const int iv1(23);

const auto p(&iv1);//const int *保留了底层

int iv2(90);

int * const ip2(&iv2);

auto p2(ip2);//int *忽略了顶层

int i3(45);

p2 = &i3;//*p2=45

cout <<" p = "<< typeid(p).name() <<endl;

cout << "p2 = " << typeid(p2).name() << endl;

cout << "p2 = " << *p2 << endl;

 

decltype:类型拷贝

int ci(49);

decltype(ci) dci(56);

 

int i(42), *p(&i), &r(i);

int j(45);

decltype(r) b(i);

decltype(p) c(&ci);

decltype(b) e(j);

cout << b <<"  "<< *c<<"  " << e << endl;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值