Pointer comaprison in pyroot

Hello,

I’d like to compare pointer I get from compiled c++ objects inside pyroot.
As an example I’m compiling and loading :

class A { public: int m; }; class B{ public: B(){a=NULL;} A* a; };

And then using them like that in pyroot :

a = ROOT.A() a.m=42 b = ROOT.B() b.a = a

At this point I have :

[code]>>> b.a == a
False

b.a is a
False
[/code]

Is this expected ? How can I make sure b.a points really to a ?

As a side question : how will python manage the a object ? If I do ‘del(a)’, will b.a count as a reference to a (hence python won’t delete it as long as b lives) ?

Cheers,

P.A.

Hi,

[sorry for responding late, but I’ve been away]

At issue is that the two are not bound the same. The ROOT.A() result is carried as an “A” object, the b.a member is carried as a “A*” pointer. The result being that if you take a python reference to it, it can be changed underneath with that change propagating, and hence the two don’t behave the same and thus are not the same. Example (continuing where your code left off):[code]>>> print b.a.m
42

aofb = b.a
a2 = ROOT.A()
a2.m = 13
b.a = a2
print aofb.m
13

[/code]
To compare whether both of them are the same, you can use AddressOf (i.e. make the assumption that if both point to the same address, they’re the same object):[code]>>> print ROOT.AddressOf(b,‘a’)[0] == ROOT.AddressOf(a)[0]
True

[/code]
HTH,
Wim