Beginner: How does an object delete itself?

ylixir ylixir at gmail.com
Sun Sep 21 08:41:24 PDT 2008


nobody wrote:
> Hello. I just started using OOP and had a question.
> 
> I have something like this:
> 
> class Foo{
> ..
>     private void deleteMyself()
>     {
>         this.delete;
>         foo.length--;
>     }
> ..
> }
> 
> Foo[] foo;
> 
> But this obviously doesn't work.
> The problem is, how do I know what position in the array the object is, and 
> how do I delete it?
> I don't want empty elements in my array. 
> 
> 

you could do some wizardry to get something like that to work, but it 
sounds like such an awkward situation to be at in the first place. maybe 
if you posted a little more context around that bit, someone could help 
you find a design pattern that would eliminate the need to do that 
altogether.

honestly, in most cases, something like that wouldn't be a good idea. 
what if the class was used later in something other than an array?


More information about the Digitalmars-d-learn mailing list