我陷入了这个错误:
gcc.compile.c ++ Physics / HelicityAmplitude / bin / gcc-4.8.3 / debug / HelicityDecayTree.o在/cvmfs/cluster/gcc/gcc-4.8.3/include/c++/4.8.3/algorithm:62包含的文件中:0,来自/cluster/compwa_externals/boost_1_55_0/include/boost/move/algorithm.hpp:23,来自/cluster/compwa_externals/boost_1_55_0/include/boost/move/move.hpp:24,来自/ cluster / compwa_externals / boost_1_55_0 /include/boost/unorder/detail/util.hpp:19,来自/cluster/compwa_externals/boost_1_55_0/include/boost/unorder/detail/buckets.hpp:14,来自/ cluster / compwa_externals / boost_1_55_0 / include / boost / unordered /detail/table.hpp:10,来自/cluster/compwa_externals/boost_1_55_0/include/boost/unorder/detail/equivalent.hpp:14,来自/cluster/compwa_externals/boost_1_55_0/include/boost/unordered/unordered_set.hpp:17 ,来自/cluster/compwa_externals/boost_1_55_0/include/boost/unordered_set.hpp:16,来自/cluster/compwa_externals/boost_1_55_0/include/boost/graph/adjacency_list.hpp:21,来自Physics / HelicityAmplitude / HelicityDecayTree.hpp:17,来自Physics / HelicityAmplitude / HelicityDecayTree.cpp:12:
/cvmfs/cluster/gcc/gcc-4.8.3/include/c++/4.8.3/bits/stl_algo.h:在'_RandomAccessIterator std :: __ find(_RandomAccessIterator,_RandomAccessIterator,const _Tp&,std :: random_access_iterator_tag)的实例中使用_RandomAccessIterator = __gnu_cxx :: __ normal_iterator>; _Tp = HelicityFormalism :: ParticleState]':
/cvmfs/cluster/gcc/gcc-4.8.3/include/c++/4.8.3/bits/stl_algo.h:4441:45:要求来自'_IIter std :: find(_IIter,_IIter,const _Tp&)[带有_IIter = __gnu_cxx :: __ normal_iterato r>; _Tp = HelicityFormalism :: ParticleState]'Physics / HelicityAmplitude / HelicityDecayTree.cpp:59:61:从此处需要
/cvmfs/cluster/gcc/gcc-4.8.3/include/c++/4.8.3/bits/stl_algo.h:166:17:错误:'operator =='不匹配(操作数类型为'HelicityFormalism :: ParticleState '和'const Helicit yFormalism :: ParticleState')如果(* __ first == __val)
我看到他正在要求对ParticleState进行const与非const的比较。但是我真的不明白他为什么要进行这种比较。我的相关代码如下:
该类的标题:
class HelicityDecayTree {
boost::adjacency_list<> decay_tree_;
std::vector<ParticleState> particles_;
public:
void createDecay(const ParticleState &mother,
const ParticleStatePair &daughters);
}
以及该成员函数的来源:
void HelicityDecayTree::createDecay(const ParticleState &mother,
const ParticleStatePair &daughters) {
// add particles to the list
unsigned int mother_vector_index;
unsigned int daughter1_vector_index;
unsigned int daughter2_vector_index;
if (std::find(particles_.begin(), particles_.end(), mother)
== particles_.end()) {
mother_vector_index = particles_.size();
particles_.push_back(mother);
}
else {
mother_vector_index = std::distance(particles_.begin(),
std::find(particles_.begin(), particles_.end(), mother));
}
if (std::find(particles_.begin(), particles_.end(), daughters.first)
== particles_.end()) {
daughter1_vector_index = particles_.size();
particles_.push_back(daughters.first);
}
else {
daughter1_vector_index = std::distance(particles_.begin(),
std::find(particles_.begin(), particles_.end(), daughters.first));
}
if (std::find(particles_.begin(), particles_.end(), daughters.second)
== particles_.end()) {
daughter2_vector_index = particles_.size();
particles_.push_back(daughters.second);
}
else {
daughter2_vector_index = std::distance(particles_.begin(),
std::find(particles_.begin(), particles_.end(), daughters.second));
}
// then make the correct inserts into the vector and link appropriately
boost::add_edge(mother_vector_index, daughter1_vector_index, decay_tree_);
boost::add_edge(mother_vector_index, daughter2_vector_index, decay_tree_);
}
和ParticleState结构:
struct ParticleState {
int particle_id_;
std::string name_;
Spin J_;
Spin M_;
};
Afaiu他应该为两个const ParticleStates合成operator ==,但是由于某种原因,find方法要求为1个参数提供非const版本。
提前谢谢,史蒂夫
好的,我忘记了编译器不会合成operator ==。所以我只是想念
bool operator==(const ParticleState &rhs) const {
...
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句