3 ms·
C++ also has references, which are like pointers in some ways, except that references cannot be null: Object& obj = other_obj; For this reason, when passing
by jcrites 8y ago
C++ also has references, which are like pointers in some ways, except that references cannot be null:
Object& obj = other_obj;
For this reason, when passing objects by reference, references should be preferred to pointers where possible. Consequently, I would translate Java code like:
void f(Object obj) { ... }
Object obj = ...
f(obj);
Into C++ code like:
void f(Object& obj) { ... }
Object& obj = ...
f(obj);
(Setting aside various other concerns like move semantics and const-correctness.)
- Koshkin 8y agoA nice thing about references (to classes) is that you can use the dot and not the silly arrow which I don't know why exists in the first place.