Beginner: How does an object delete itself?
nobody
somebody at somewhere.com
Sun Sep 21 09:38:59 PDT 2008
I'm still only a beginner, but this class is only used in one array ;)
"ylixir" <ylixir at gmail.com> wrote in message
news:gb5pv5$2f87$1 at digitalmars.com...
> 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