我试图建立一个名为Setop的类,该类提供集合操作,包括交集,union等。因此,我尝试使用C ++模板来实例化它。在Setop中,我使用QSet来存储集合的元素。我的代码如下所示:
设定档
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 :: tuples :: tuple传递给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'
请问这些错误是什么意思,以及如何纠正它们?
最佳答案
From doc:
QSet类是提供基于散列表的集合的模板类。
...
在内部,QSet被实现为QHash。
放在QHash
内的任何值都应定义两者
operator==(const T& other)
uint qHash ( const T * key )
关于c++ - 在Qt中使用带有QSet和boost::tuples::tuple的模板时,没有匹配错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13703663/