H
Howard
Hi,
I've got a program whose main object contains an array of "cells", each
of which contains an array of "sub-cells", each of which contains an array
of "sub-sub-cells". The cells, subcells and subsubcells are three
user-defined types, each of which contains some program logic as well as
some drawing capabilities. Since all cells (and subcells and subsubcells)
will utilize identical drawing "settings", I'm using a single settings
object, owned by the main program object, which is referred to by the
various cell-type objects when drawing (to control colors, etc.).
The issue I'm having stems from the desire to avoid pointers in favor of
references. As it is, the three cell-types each have an Initialize function
which gets passed a pouinter to the main object's settings object. This is
used to set a member pointer to that object, and later dereferenced to get
at the specific settings when it's a given cell-type object's turn to draw
itself.
What I wanted to do was to use a reference variable instead of a pointer
to that main settings object. But this can't be set from Initialize, since
a reference can't be reseated. And, I can't initialize it via the
constructor, since the cells are all in member arrays of their containing
parent, and the objects in a member array are always initialized via the
default constructor.
What's the best way to proceed? Is my current use of a member pointer
the best/only way? Or is there a clean way to use a member reference here?
I don't mind the pointers, really (and can use asserts to help prevent later
errors in coding that might accidently lead to my attempting to dereference
the pointer prior to its getting initialized properly). But I prefer
references to pointers, and wondered if there was a way to use them here,
without it being a big, unmaintainable, task.
Thanks,
-H
I've got a program whose main object contains an array of "cells", each
of which contains an array of "sub-cells", each of which contains an array
of "sub-sub-cells". The cells, subcells and subsubcells are three
user-defined types, each of which contains some program logic as well as
some drawing capabilities. Since all cells (and subcells and subsubcells)
will utilize identical drawing "settings", I'm using a single settings
object, owned by the main program object, which is referred to by the
various cell-type objects when drawing (to control colors, etc.).
The issue I'm having stems from the desire to avoid pointers in favor of
references. As it is, the three cell-types each have an Initialize function
which gets passed a pouinter to the main object's settings object. This is
used to set a member pointer to that object, and later dereferenced to get
at the specific settings when it's a given cell-type object's turn to draw
itself.
What I wanted to do was to use a reference variable instead of a pointer
to that main settings object. But this can't be set from Initialize, since
a reference can't be reseated. And, I can't initialize it via the
constructor, since the cells are all in member arrays of their containing
parent, and the objects in a member array are always initialized via the
default constructor.
What's the best way to proceed? Is my current use of a member pointer
the best/only way? Or is there a clean way to use a member reference here?
I don't mind the pointers, really (and can use asserts to help prevent later
errors in coding that might accidently lead to my attempting to dereference
the pointer prior to its getting initialized properly). But I prefer
references to pointers, and wondered if there was a way to use them here,
without it being a big, unmaintainable, task.
Thanks,
-H