J
Jess
Hello,
I understand that if a function "f" has a local variable "a", and
after it returns, "a" vanishes. If "f" returns "a" as a result, then I
noticed the following:
1. if the return type is "a&", then compiler complains reference to
the local variable "a".
2. if the return type is "a", then everything works fine.
I think this is because in the first case, the return is copy-by-
reference, and we can't reference a local var. In the second case, it
is a copy-by-value, and it's correct because we can copy the value
from a local var, is this right?
Thanks!
I understand that if a function "f" has a local variable "a", and
after it returns, "a" vanishes. If "f" returns "a" as a result, then I
noticed the following:
1. if the return type is "a&", then compiler complains reference to
the local variable "a".
2. if the return type is "a", then everything works fine.
I think this is because in the first case, the return is copy-by-
reference, and we can't reference a local var. In the second case, it
is a copy-by-value, and it's correct because we can copy the value
from a local var, is this right?
Thanks!