所以,是的,标题几乎是整个问题。正如您从下面的代码片段中看到的那样,我确实实现了operator<
,所以我不知道发生了什么。
这是代码:
namespace {
struct Transition {
string name;
StatePtr toState;
Transition(string s = string(), StatePtr state = nullptr)
: name(move(s))
, toState(move(state))
{}
friend bool operator==(Transition const& lhs, Transition const & rhs) {
return lhs.name == rhs.name && lhs.toState == rhs.toState;
}
friend bool operator<(Transition const & lhs, Transition const & rhs);
};
struct State {
string name;
set<TransitionPtr> transitions;
explicit State(string s = string())
: name(move(s))
{}
void addTransition(string s, StatePtr sp = nullptr){
TransitionPtr new_t = make_transition(s, sp);
for(auto& t : transitions){
if(t == new_t){
return;
}
}
transitions.insert(move(new_t)); // This is where the error happens.
}
};
}
bool operator<(StateMachine::Transition const & lhs, StateMachine::Transition const & rhs) {
return lhs.toState.get() < rhs.toState.get();
}
错误信息是:
在 ../llvm_opt_pass/cgd.cpp:3 中包含的文件中:在 /srv/scratch/sigubufo/clang/stable/3.1_src/llvm/include/llvm/Instructions.h:23 中包含的文件中:在/中包含的文件中srv/scratch/sigubufo/clang/stable/3.1_src/llvm/include/llvm/ADT/ArrayRef.h:13:在/srv/scratch/sigubufo/clang/stable/3.1_src/llvm/include/llvm中包含的文件中/ADT/SmallVector.h:24:在 /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/memory:85 中包含的文件中: /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/unique_ptr.h:486:14:错误:没有匹配的调用函数到 'std::less<_CT>' 类型的对象返回 std::less<_CT>()(__x.get(), __y.get()); ^~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/stl_function.h:237:20:注意:在函数模板的实例化中要求专门化 'std::operator<<::StateMachine::Transition, std::default_delete<::StateMachine::Transition>, ::StateMachine::Transition, std::default_delete<::StateMachine::Transition>>这里 { 返回 __x < __y; } ^
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/stl_tree.h:1285:13:注意:在成员函数的实例化中'std::less::StateMachine::Transition, std::default_delete<::StateMachine::Transition> > >::operator()' 在这里请求 __comp = _M_impl._M_key_compare(_KeyOfValue()(__v), _S_key(__x )); ^
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/stl_set.h:424:9:注意:>在函数的实例化中模板特化 'std::_Rb_tree::StateMachine::Transition, std::default_delete<::StateMachine::Transition>>, std::unique_ptr<::StateMachine::Transition, std::default_delete<::StateMachine::过渡> >,std::_Identity::StateMachine::Transition,std::default_delete<::StateMachine::Transition> > >,std::less::StateMachine::Transition,std::default_delete<::StateMachine: :Transition> > >, std::allocator::StateMachine::Transition, std::default_delete<::StateMachine::Transition> > ::_M_insert_unique::StateMachine::Transition, std::default_delete<::StateMachine: :Transition> > >' 在这里请求 _M_t._M_insert_unique(std::move(__x));^
../llvm_opt_pass/cgd.cpp:72:17:注意:在成员函数 'std::set::StateMachine::Transition、std::default_delete<::StateMachine::Transition>>、std::less 的实例化中::StateMachine::Transition, std::default_delete<::StateMachine::Transition> > >, std::allocator::StateMachine::Transition, std::default_delete<::StateMachine::Transition> >> >::在此处请求插入'transitions.insert(move(new_t)); ^
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/stl_function.h:236:7:注意:候选函数不可行:对于第一个参数,没有从 'pointer' (aka '::StateMachine::Transition *') 到 '::StateMachine::Transition *&&&' > 的已知转换;运算符()(常量_Tp& __x,常量_Tp& __y)常量