[C++-sig] operator in return false while operator == return true

Stefan Seefeld seefeld at sympatico.ca
Fri Sep 24 16:27:51 CEST 2010


I don't quite understand what you are trying to do. Please provide a 
little more detail. Your current mail requires far too much 
second-guessing to be useful.

On 09/24/2010 10:08 AM, Simon W wrote:
> Hi,
> Im really scared because I fear a fundamental issue concerning the 
> script system in my game engine.
> In C++, I have a class. In my class I map data to GameObject like:
> *class
> {
>     map<GameObject*, Data> .....
> }*

OK. (Naming this class would help the discussion, though.)

> As you see, I use the pointer as key.
> When I from c++, in the same class, call a python function I pass the 
> key like this:
> *class::callPythonFunctions()
> {
> boost::python::get_override("callbackFunction")(boost::python::object(boost::python::ptr(gameobject))); 
> // the variable /gameobj /is of type GameObject*
> }
> *


> When I recieve the call in python I do some checks like this:
> *def callbackFunction(self, gameobj):
>    for x in self.mydict.keys():
>      print("Checking")
>      print(gameobj == self.mydict)
>      print(gameobj in self.mydict)*

This looks wrong. You iterate over 'x', but don't use it in the loop. 
May I assume that 'mydict' relates to the above map<GameObject*, Data> 
in the unnamed class ?

> The above will print something like:
> /....
> Checking
> True
> False
> .../

This suggests that 'gameobj' compares equal to the 'mydict' object, but 
that it is not itself included in the sequence returned by mydict.keys().

> I do have a overloaded == operator. But how can I fix so that python 
> checks for my pointer and not the PyObject* pointer ?

What type do you consider providing an operator== for ?



       ...ich hab' noch einen Koffer in Berlin...

More information about the Cplusplus-sig mailing list