freestandingreferences.cpp
来自「ThinkingC++中文版」· C++ 代码 · 共 29 行
CPP
29 行
//: C11:FreeStandingReferences.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
#include <iostream>
using namespace std;
void main() {
// Ordinary free-standing reference:
int y;
int& r = y;
// When a reference is created, it must be initialized to a live object. However, you can also say:
const int& q = 12; // (1)
// References are tied to someone else's storage:
const int a = 200;
const int& k = a;//常量引用
// const int& k = y;//ok
// k = 20; //error
int* pi = &y;
int* & pj = pi;//pj为整数指针的引用
/*
int x = 0; // (2)
int& *p;
p = &x // (3)
*/
} ///:~
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?