偶尔看到的c11新特性1

1基于范围的for循环
c++

double array[5] = {1.1,2.2,3.3,4.4,5.5}
for(double x : array)
{
    cout << x << " ";
}
cout << endl;

2auto数组

c11容许以下代码spa

std::vector<double> scores;
auto pv = score.begin();

3c11初始化数组能够省略等号,能够直接所有初始化为0:指针

double array[4] {};//初始化为0.

4右值引用code

double && rref = std::sqrt(36.00);
double j = 15.0;
double && jref = 2.0*j +18.5;
//移动语义(move semantics)

5在c++primer plus 264页orm

struct free_throws
{
std::string name;
int made;
int attempts;
float percent;
}
...
const free_throws & clone(free_throws & ft)
{
free_throws *pt;
*pt = ft;
return *pt;
}

free_throws & jolly = clone(three);

个人理解是返回了一个free_throws类型的一个const引用(对么?)这个引用指向(指针说指向,引用应该怎么表述?)的空间和& ft指向的空间不是同一个.three

要记得delete回收空间,(new被隐式)ci