On Sat, 19 Feb 2005 13:58:59 -0800, "Larry Brasfield"
<do***********************@hotmail.com> wrote:
"Gonçalo Rodrigues" <op*****@mail.telepac.pt> wrote in message
news:0s********************************@4ax.com... Hi all,
Greetings.
I have a base class, call it Object, that implements operators new and
delete.
Now suppose there is also a class, call it Derived, deriving from
Object. It has the feature that *all* its instances are statically
allocated so I have to override new and delete.
That fact does not (or should not) drive the decision to
override the allocation functions. Is there anything about
your 'Derived' class that causes it to behave incorrectly
if dynamically allocated? Is there any reason to block
dynamic creation of 'Derived' objects? If no, then I see
no reason that you have to override.
Since *all* instances are statically allocated (and already fully
initialized by the time the program starts) I should just prevent
creation of objects from the heap by making operator new private. Is
this correct?
Nothing you have stated leads me to agree with your "should".
What bad thing might happen if your "should" is violated?
And what about operator delete? Make it also private?
Except in rare circumstances, the access to those
functions should be the same.
Or is there a "better way" (for suitable values of better)?
You have not given enough information to gauge "better".
Yes, my appologies, my description is incomplete. But actually, your
answer is not, because I can't think of anything bad happening if an
instance of Derived is allocated on the heap.
with my thanks and regards,
G. Rodrigues