Confused about class equality

strtr strtr at spam.com
Tue Apr 6 17:37:12 PDT 2010


bearophile Wrote:

> strtr:
> > Is it possible to have different vpointers/monitors pointing to the same object?
> 
> I think this questions is meaningless. Those pointers don't point to objects.
> 
> And the "is" operator compared class references, not vpointers/monitors.
> 
> Bye,
> bearophile

The subject wasn't for nothing :)
How I understand it now, vptr points to the Class's vtable.
This would mean they should be the same for references to the same object or can these references also hold a pointer to a pointer to the vtable?  
I'm not sure where the monitor points to, though. 

The problem surfaces when I wanted to do a simple check for objects equality between references. I though I should use "is" for this. But to my astonishment it failed even though I know the references point to the same object, I think.
I checked whether the references pointed to the same object by giving all objects a unique value and changing this value via one of the references and then checking whether the value was the same for the other reference.
Conclusion: two references fail "is", but changing the value via one of the references also changed the value got via the other reference.

My solution for now is simply checking for equality via this unique value but I hoped I could use "is" for this :)

I suspect I totally misunderstand something; hope to learn something again :)


More information about the Digitalmars-d-learn mailing list