我试图构建一个名为Setop的类,它提供集合操作,包括交叉、union等。因此,我尝试使用C++模板来实例化它。在Setop中,我使用QSet存储集合的元素。我的代码如下所示:
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]);
}下面是我尝试使用模板类的方式,我传递了boost::tuple::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());
}
}编译器生成以下错误:
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'请问这些错误是什么意思,以及如何纠正?
发布于 2012-12-04 13:48:18
从医生那里:
QSet类是一个模板类,它提供了基于哈希表的集合. ..。 在内部,QSet被实现为一个QHash。
放置在QHash中的任何值都应该定义这两个
operator==(const T& other)
uint qHash ( const T * key )https://stackoverflow.com/questions/13703663
复制相似问题