引用作为函数返回后,函数调用可以作为左值
#include <iostream>
//引用的含义:int &a 实际上是 int * const a 本质上就是一个指针常量
int& swap() { static int a = 10; return a; } int main() { int &ref = swap(); std::cout << "ref=" << ref << std::endl; swap() = 1000; std::cout << "ref=" << ref << std::endl; }
浙公网安备 33010602011771号