void func( const int & v2)
{
//cout << "&v1 = "<< &v1 << endl;
cout << "&v2 = " << &v2 << endl;
//std::cout <<"v1 = "<< v1 << ' ';
std::cout <<"v2 = "<< v2 << ' ';
}
int _tmain(int argc, _TCHAR* argv[])
{
int i = 0;
cout <<"&i = "<< &i << endl;
func(i++);
system("pause");
return 0;
}
&i = 0115FB70
& v2 = 0115FAA4
v2 = 0 请按任意键继续. . .
可以看到在
经过推理,最终落脚在i++,个人认为,在执行i++的之后会由编译器先制作一个副本变量,存储++之前需要处理的值,作用域类被严格限制。
最后做了个demo验证
#include "stdafx.h"
#include <iostream>
using namespace std;
void func(const int& v1,const int & v2)
{
cout << "&v1 = "<< &v1 << endl;
cout << "&v2 = " << &v2 << endl;
std::cout <<"v1 = "<< v1 << ' ';
std::cout <<"v2 = "<< v2 << ' ';
}
int _tmain(int argc, _TCHAR* argv[])
{
int i = 0;
int a = 0;
cout << "&a = " << &a << endl;
const int &b = a++;
cout << "&b = " << &b << endl;
cout << "&a = " << &a << endl;
cout <<"&i = "<< &i << endl;
func(++i, i++);
system("pause");
return 0;
}
希望大神可以帮忙找到标准语意相关的标准答案。