From: | Allan Odgaard |
Date: | 16 Dec 99 at 02:52:47 |
Subject: | Re: Optimizing (Was: Re: Getting desperate!) |
From: Allan Odgaard <Duff@DIKU.DK>
On 15-Dec-99, Steffen wrote:
[ calling with a pointer vs. an instance ]
> Yes, i know. That's why i didn't write it was the *only* way to do it. If
> you're absolutely sure you know what you're doing, you can use that aproach,
hmm... you should also know what you're doing, when calling with a copy of the
object. Since all member functions that change instance data variables, will
have no permanent effect.
> but it is still safer to work with structures that are read-only, wich is
> what i see is one of the points of C++ [...]
Well, you could declare the read-only instance data as 'protected' and provide
member functions which would return the variables. This will give you the same
advantage, perhaps even better, as you'd get a compiler warning, when trying
to overwrite the data (in contrary to your 'recommended' solution) - and you
won't suffer from any cpu and/or code overhead.
Regards Allan