0

I'm using Qt and I want to declare following container:

QMap<QUrl , QSet<ClassSharedPtr> > map;

Here ClassSharedPtr is the boost shared ptr of class "Class".

typedef boost::shared_ptr<const Class> ClassPtr;

I'm getting following errors after adding header file #include :

error: no matching function for call to ‘qHash(const boost::shared_ptr<const Class>&)’
BSalunke
  • 11,499
  • 8
  • 34
  • 68

1 Answers1

0

QSet's value data type must be an assignable data type. In addition, the type must provide operator==(), and there must also be a qHash() function in the type's namespace that returns a hash value for an argument of the values's type.

So, you should implement qHash() function for boost::shared_ptr<const Class>.

namespace boost {

uint qHash(const boost::shared_ptr<const Class> &key, uint seed = 0)
{
    const Class *ptr = key.get();
    return uint(ptr) ^ seed;
}

}
Meefte
  • 6,469
  • 1
  • 39
  • 42