2 ms·
I am not a heavyweight C++ user (also a very lightweight C and a, uhm... featherweight Pascal user), but I'd think using a C++ reference as a method argument sh
by rzzzt 6y ago
I am not a heavyweight C++ user (also a very lightweight C and a, uhm... featherweight Pascal user), but I'd think using a C++ reference as a method argument should be as safe as Pascal's var parameters.
Is returning references frequently done in C++? I have only seen it in ostream's << operator-like constructs where you want to chain multiple calls to the same object.
- pjmlp 6y agoNot necessarily, although it is seldom seen I the wild, you can cast a null pointer into a reference. Another source of issues might be the creation of temporaries. Yes, in index operator as well.
- benibela 6y ago>Is returning references frequently done in C++? It is rather common to avoid copying returned objects. (perhaps it becomes less common with std::move ?) For example, the [] operator on the standard collections returns a reference, so the item can be modified There Pascal has another clever idea. You can overload [] for reading and writing separately. Then x[k] := v becomes x.setItem(k, v)