[comp.lang.c++] whoops, lets chuck this object

llama@eleazar.dartmouth.edu (Joe Francis) (08/01/90)

I have a class which has a limit on the number of instances that can
exist at any one time.  Currently my constructor checks the limit,
and if we are over it a flag in my object is set.  It is then the
callers responsibility to check the flag, call delete if necessary
(if the object is free, not local), and do whatever needs to be done
to keep the user happy (yeah, right).

This is very ugly to me.  What I want is to be able to do the delete
part (and the determination of whether delete needs to be done) in
the constructor, or some such.  But I don't think it's possible to
make this determination, and even if it were, would it be legit to
call delete on an object from within it's own constructor?

As you can see, my inexperience with C++ is causing me some basic 
design confusion.  I would appreciate input on how to accomplish
what I want (whatever that is) in a manner more elegant than the
one I am using now.

I just want attempts to create local or free objects to bounce like
a bad check if my limit is exceded, and for the caller to be told
this in a respectable way, and not have to do to much paperwork as
a result.

Thanks for any ideas,
Joe
----------------------------------------------------------------------------
"Read My Lips: No Nude Texans!" - George Bush clearing up a misunderstanding