来自:Google groups comp.lang.c++


  1. when a temporary is assigned to a reference inside a {} block, it’s lifetime is extended to the lifetime of a reference.
#include <iostream>
using namespace std;

int main()
{
	int a = 10;
	int & ra = a;
	{
		int t = 12;
		ra = t;
	}

	cout << ra << endl;
}

本文地址:http://zisxks.com/2014/04/21/Hidden-Features-and-Dark-Corners-of-Cplusplus-STL
分享到 Share: 0

欢迎转载,转载请注明作者及出处zisxks.com,请勿用于商业用途