0

I tried to build a class named Setop that provides set operations including intersection, union et al. So I tried to use template of C++ to instantiate it. In Setop, I use QSet to store the elements of a set. My code looks like this:

setop.h

    template <typename T> class SetOp {
    public:
        SetOp(std::vector<T> &_input);
void _union(SetOp<T> &_set2);
    QSet<T> _intersection(SetOp<T> &_set2);
    QSet<T> _diff(SetOp<T> &_set2);
    QSet<T> _diff(QSet<T> &_set1,QSet<T> &_set2);
    void outputElement();
    QSet<T> getSet(){return mySet;}
    std::vector<T> getVecFromQSet();
    private:
        QSet<T> mySet;
    };

setop.cpp:

template <typename T> SetOp<T>::SetOp(std::vector<T> &_input)
{
    for(int i = 0; i < (int)_input.size(); ++i)
        mySet.insert(_input[i]);
}

Here is how I tried to use the template class, I pass boost::tuples::tuple to Setop:

    void MainWindow::setOp(std::vector<std::vector<boost::tuples::tuple<float,int,int,int> > > &_pointSet)
    {
       std::vector<std::vector<boost::tuples::tuple<float,int,int,int> > > merged;  
       while(!_pointSet.empty()) {
           BOOST_AUTO(it,_pointSet.begin());
           BOOST_AUTO(itn,_pointSet.begin() + 1);
           SetOp<boost::tuples::tuple<float,int,int,int> > set1((*it)),set2((*itn));
           for(; itn != _pointSet.end();) {
               //           SetOp<boost::tuples::tuple<float,int,int,int> > temp = set1;
//           if(!temp._intersection(set2).isEmpty()) {
//               set1._union(set2);
//                itn = _pointSet.erase(itn);
//           }
//           else
//               ++itn;
           }
//       merged.push_back(set1.getVecFromQSet());
       }
    }

The compiler generates the following errors:

c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore\qhash.h:882: error:no matching function for call to 'qHash(const boost::tuples::tuple<float, int, int, int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>&)'
c:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtCore\qhash.h:225: error:no match for 'operator==' in 'key0 == ((QHashNode<boost::tuples::tuple<float, int, int, int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, QHashDummyValue>*)this)->QHashNode<boost::tuples::tuple<float, int, int, int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, QHashDummyValue>::key'

What do these erroes mean and how to correct them, please?

user957121
  • 2,946
  • 4
  • 24
  • 36
  • Related: http://stackoverflow.com/questions/9126470/how-to-write-qhash-for-a-qsetsomeclass-container – Vaughn Cato Dec 04 '12 at 13:13
  • @VaughnCato There is a float value in boost::tuples::tuple. It's hard to implement operator== for a float value, isn't it? – user957121 Dec 04 '12 at 13:48
  • dont use QSet then... use a std collection or a boost collection. Also, why does SetOp.intersection(SetOp ) return a QSet? it is a bit inconsistent... – UmNyobe Dec 04 '12 at 14:06

1 Answers1

1

From doc :

The QSet class is a template class that provides a hash-table-based set.
...
Internally, QSet is implemented as a QHash.

Any value put inside a QHash should define both

operator==(const T& other)
uint qHash ( const T * key )
UmNyobe
  • 22,539
  • 9
  • 61
  • 90