|
![](/i/fill.gif) |
Christopher James Huff <cja### [at] earthlink net> wrote:
> Pass everything by reference
That can be problematic.
Suppose you have something like this:
class ItemContainer
{
private:
Int numberOfItems;
public:
...
Int size() { return numberOfItems; } // <- returns a reference
...
};
...
ItemContainer container;
// add things to 'container'
Int foo = container.size(); // <- gets a *reference*
foo -= 100; // Ooops! The container breaks badly!
The thing is that in principle the code is not doing anything malign
on purpose. It's only natural that you take eg. the size of the container
to a variable and then use this variable for example as a loop counter
(eg. to go through all the items in the container).
The big problem is that since your variable is actually a reference
to the original 'numberOfItems' variable, you'll end up breaking the
container.
I don't know enough about Java to know how this problem is avoided
there.
--
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -
Post a reply to this message
|
![](/i/fill.gif) |