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?

4

1 回答 1

1

来自文档

QSet 类是一个模板类,它提供了一个基于散列表的集合。
...
在内部,QSet 被实现为 QHash。

放在 a 中的任何值QHash都应该定义两者

operator==(const T& other)
uint qHash ( const T * key )
于 2012-12-04T13:48:18.803 回答