Code:// // g++ -o test -l IceUtil test.cc // #include <cassert> #include <iostream> #include <IceUtil/Handle.h> #include <IceUtil/Shared.h> class Demo : public ::IceUtil::SimpleShared { public: Demo (int x = 0) : x_(x) { } bool operator== (const Demo& d) { ::std::cout << "erroneous object comparison invoked" << ::std::endl; return x_ == d.x_; } protected: virtual ~Demo () { } private: int x_; }; typedef ::IceUtil::Handle<Demo> DemoPtr; int main () { DemoPtr a (new Demo (1)); DemoPtr b (new Demo (1)); assert (a == b); // this succeeds, but should fail according to the documented semantics // Handle.h // // template<typename T, typename U> // inline bool operator==(const HandleBase<T>& lhs, const HandleBase<U>& rhs) // { // T* l = lhs.get(); // U* r = rhs.get(); // if(l && r) // { // return *l == *r; // } // return !l && !r; // } // // Sometimes less is more. How about simply: return lhs.get() == rhs.get(); // return 0; }

Reply With Quote