我遇到了这个错误:
gcc.compile.c ++ Physics / HelicityAmplitude / bin / gcc-4.8.3 / debug / HelicityDecayTree.o In 文件包括 /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/unordered/detail/util.hpp:19, 来自/cluster/compwa_externals/boost_1_55_0/include/boost/unordered/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/unordered/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:In 实例化'_RandomAccessIterator std :: __ find(_RandomAccessIterator,_RandomAccessIterator,const _Tp&amp ;,, std :: random_access_iterator_tag)[与_RandomAccessIterator = __gnu_cxx :: __ normal_iterator&gt ;; _Tp = HelicityFormalism :: ParticleState]”:
/cvmfs/cluster/gcc/gcc-4.8.3/include/c ++ / 4.8.3 /比特/ stl_algo.h:4441:45: 需要'_IIter std :: find(_IIter,_IIter,const _Tp&)[with _IIter = __gnu_cxx :: __ normal_iterato r&gt ;; _Tp = HelicityFormalism :: ParticleState]” 物理/ HelicityAmplitude / HelicityDecayTree.cpp:59:61:需要 这里
/cvmfs/cluster/gcc/gcc-4.8.3/include/c ++ / 4.8.3 /比特/ stl_algo.h:166:17: 错误:'operator =='不匹配(操作数类型是 'HelicityFormalism :: ParticleState'和'const Helicit yFormalism :: ParticleState”) if(* __ first == __val)
我看到他要求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版本......
提前, 史蒂夫
答案 0 :(得分:0)
好的,我忘了编译器不会合成运算符==。所以我只是缺席了
bool operator==(const ParticleState &rhs) const {
...
}