I somehow start to try to understand C++ and get confused with "undefined", "unspecified".
References are widely documented, but I didn't find the the answer to my "specific" question.
What about a reference of a value passed by reference?
I have tested this with the following code:
#include <iostream>
int func(int& a)
{
int b=a;
++b;
std::cout << "[func] b: " << b << std::endl;
return b;
}
int func2(int& a)
{
int& b=a;
++b;
std::cout << "[func2] b: " << b << std::endl;
return b;
}
int main()
{
int a=1;
std::cout << "a: " << a << std::endl;
func(a);
std::cout << "a after func: " << a << std::endl;
func2(a);
std::cout << "a after func2: " << a << std::endl;
return 0;
}
and got the output:
a: 1
[func] b: 2
a after func: 1
[func2] b: 2
a after func2: 2
It seems to do what I expect, but is this the behavior mandated by the standard?