5 ms·
You probably did intend it to be a copy if you're binding it to a variable and need it to be non-const (like in the example)!
by mehrdadn 6y ago
You probably did intend it to be a copy if you're binding it to a variable and need it to be non-const (like in the example)!
- secondcoming 6y agoAh, but you knew that because that's how the code was written! If it was instead String foo = "bar"; auto baz = foo; you don't know for sure. But the code compiles so it obviously ok!
- mehrdadn 6y agoNo, I'm saying even in that case you know it was intended to be a copy. If you wanted that to be a reference then you'd either (a) just do the obvious thing which is to just use the original variable name instead of creating a new variable out of the blue for no reason, (b) leave a comment explaining why you're not doing the aforementioned obvious thing, or (c) use a self-explanatory variable name to provide the explanation instead of a comment.