我正在实现六度凯文培根问题并为演员节点编写一个类。我可以使用 set 而不是 hash_set 容器来保存用户定义的类。为什么?错误消息显示:错误 C2440: 'type cast' : cannot convert from 'const ActorGraphNode' to 'size_t' 1> 没有可以执行此转换的用户定义转换运算符,或者无法调用该运算符....
#include <hash_set>
#include <set>
class ActorGraphNode{
public:
string ActorName;
//hash_set<ActorGraphNode> linkedActors;
set<ActorGraphNode> linkedActors;
ActorGraphNode(string name):ActorName(name){}
void linkCostar(ActorGraphNode actor){
linkedActors.insert(actor);
actor.linkedActors.insert(*this);
}
bool operator<( const ActorGraphNode& a ) const
{ return ActorName < a.ActorName ? true : false;}
};