国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

Reference:alias

2019-11-11 05:56:22
字體:
供稿:網(wǎng)友

Rule:

1.References must be initialized when de?ned. Initialization establishes a binding.

eg: type& refname = name; //thus the value of refname is the same as name.

2.Bindings don’t change at run time, unlike pointers.

3.The target of a reference must have a location! 

 eg:void func(int &); //automatically binding when call the function.

func(i*3); //warning or error!

 Restrictions:

1.No references to refercences

2.No pointers to references

int & * p; //illegal

  But reference to pointer is ok

int* & p;

3.No arrays of reference

Notice: constant value can be modified through reference.

#include <iostream>using namespace std;int main(){    int& *p;    int x=3;    int &y=x;    const int&z=x;    cout<<"z:"<<z<<endl;    y=4;    cout<<"after y=4,z:"<<z<<endl;    x=5;    cout<<"after x=5,z:"<<z<<endl;//error here:z cannot be assigned,but it still can be modified by y or x.//  z=5;    return 0;}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 东兰县| 光山县| 南岸区| 尉犁县| 潞西市| 西宁市| 望城县| 商城县| 大同市| 龙海市| 营山县| 西和县| 青浦区| 获嘉县| 富顺县| 根河市| 弋阳县| 赤城县| 肃宁县| 玛曲县| 肇州县| 乌拉特后旗| 清流县| 铜川市| 威信县| 密云县| 扶绥县| 雷山县| 托克逊县| 太康县| 京山县| 华宁县| 肃宁县| 杭锦旗| 布尔津县| 洛川县| 宿州市| 定兴县| 大渡口区| 台州市| 南郑县|