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

首頁 > 學院 > 開發設計 > 正文

Reference:alias

2019-11-11 06:37:17
字體:
來源:轉載
供稿:網友

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;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 紫金县| 北辰区| 西丰县| 施甸县| 武安市| 融水| 平舆县| 南部县| 温宿县| 临汾市| 稷山县| 福鼎市| 镇安县| 比如县| 扶绥县| 石台县| 台南市| 南陵县| 清原| 浏阳市| 康乐县| 登封市| 乌鲁木齐县| 龙州县| 谢通门县| 高邮市| 许昌县| 茂名市| 丁青县| 黄石市| 大余县| 色达县| 紫阳县| 峨眉山市| 白玉县| 海阳市| 丹凤县| 合水县| 安泽县| 迁安市| 甘泉县|