C++ Primer 笔记 一

来源:互联网 发布:淘宝淘金币怎么用 编辑:程序博客网 时间:2024/06/08 13:21
typedef:

typedef double wage;
using wage=double;

不是直接替换关系
typedef char *pstring;
const pstring cstr;    //const pointer to char 一个指向char 的 常量 指针
const char *cstr;   // pointer to a const char  一个指针指向字符常量

basetype 改变了 从右向左看 , const仅修饰constness

auto z=z1+z2;  自动推断类型

int i=0;
const int ci=i;
auto b=ci;          b 是 int, top level被忽略掉了
auto e=&ci;           e是 const int* 因为为low level

而对reference  low high都不会被ignore
auto &g=ci;  //  仍然为常量引用 const int &
biund to ci

auto &h=42     //error
const auto &j = 42;   //    ok
引用前引入const 便可以引用常量
const int &i = 56; //OK

decltype 取类型
int i=42,*p=&i,&r=i;
decltype(r+0) b;  b is int uninitialized
decltype(*p) c; error  c is int&  must be initialized
对  dereference的指针  decltype  为 reference 型必须 intialize
decltype(i)d;  ok d is int
decltype((i))e; error   e is int & must be initialized
对于 ( expr)   有括号 变成了reference类型           ( variable) yields a reference
0 0
原创粉丝点击