Consider a code where a struct has a member variable bar
and a member reference variable that refers to bar
. For instance:
struct Foo{
double bar;
double &bar_ref=bar;
};
void receivesFoo(Foo cp_foo){
//&cp_foo.bar_ref is the same as &my_foo.bar_ref
}
int main(){
Foo my_foo;
receivesFoo(my_foo);
return 0;
}
The problem is that if you make a copy of a Foo
by, for example, passing it to a function, cp_foo.bar_ref
will refer to my_foo.bar
and not to cp_foo.bar
. How can I make it refer to cp_foo.bar
instead?
Note: I use these references variables for naming convenience, as some tutorials make it look like a possible use and I'd rather avoid all the readability issues associated with macros.