[C++-sig] dict.has_key works in a Python script, not in C++

Guillaume Seguin guillaume at paralint.com
Thu Mar 4 17:28:53 CET 2010

Great : implementing __hash__ *and* operator==() did the trick !

My implementation uses this
int hello::__hash__() const
    //Using Duff's device version of sdbm hash func
    return dbm_hash(country.c_str(), country.length());

bool hello::operator == (const hello &h) const {
    return __hash__() == h.__hash__();

With the corresponding definitions for my extension
class_<hello>("hello", init<std::string>())
    .def("__hash__", &hello::__hash__)
    .def(self == self)

Thank you,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20100304/174c19ae/attachment.html>

More information about the Cplusplus-sig mailing list