Re: References: I need a quick bit of .
On Oct 16, 6:47 pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
> xkenneth wrote:
[...]
> > binNode.h
> > ----------------
> > #ifndef BINNODE_H
> > #define BINNODE_H
> > class binNode
> > { public:
> > [...]
> > float& data;
> > };
> > #endif
> > -------------------
[...]
> Once you do, rethink your decision to store references in your nodes.
> References are very delicate things, they cannot be "re-seated" to refer
> to a different object.
Especially, in this case, a float& has absolutely no advantage
over a simple float.
> Once initialised, they refer to the same object as long as
> they live; assigning to a reference changes the object to
> which the reference refers.
I suspect that in this case, he could get by with a float
const&. But frankly, using anything but a simple float seems
very, very wrong.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
|