Python Ctypes: Wraping C++ Class With Operators
I want to wrap a small test C++ class for use in python using ctypes. The class is called Edge and has a friend comparison (==) operator. I am having difficulty implementing the co
Solution 1:
Problem is, you're trying to cast a Python object to a void *
, rather than the void *
you already attached to that object's obj
attribute.
It should be as simple as changing...
def__eq__(self, other):
return lib.compare_edge(self.obj, c_void_p(other))
...to...
def__eq__(self, other):
return lib.compare_edge(self.obj, other.obj)
The explicit call to c_void_p
should be unnecessary, since you already declared the types in the line...
lib.compare_edge.argtypes = [c_void_p, c_void_p]
Post a Comment for "Python Ctypes: Wraping C++ Class With Operators"