From: Grzegorz J. <ja...@he...> - 2004-03-02 08:08:23
|
On Sat, 28 Feb 2004, SF Markus Elfring wrote: > > Third, observe that OpenC++ uses garbage collection. The popular idiom > > that reference is a non-owning pointer is not useful in this context. > > Moreover, it can be deadly if function stores the reference passed in. > > AFAIK the original idea was then to stick to the pointers. > > One thing that I like with references is: You do not need to check for > null pointers. They must be initialized. I like it too, but: (1) Sometimes you need a special value to mark "error", "not supplied", "the end" etc., so it is convenient to use null pointer for this purpose. (2) References have different assignment semantics than pointers. Changing pointer class data members into references will most likely change the assignment semantics of the class. (3) As I already mentioned, references can potentially confuse garbage collector. So references are not just better pointers. References are references and pointers are pointers. In particular C++ is lacking native compound type that would behave as a pointer, but guarantee non-nullness. Best regards Grzegorz ################################################################## # Grzegorz Jakacki Huada Electronic Design # # Senior Engineer, CAD Dept. 1 Gaojiayuan, Chaoyang # # tel. +86-10-64365577 x2074 Beijing 100015, China # # Copyright (C) 2003 Grzegorz Jakacki, HED. All Rights Reserved. # ################################################################## |