我是C ++菜鸟,所以请不要介意您是否发现这个问题很愚蠢
我在下面的C ++中声明了map:
std::map<CartesianLocation, std::list<RadioSignal<RadioDevice>>> radioMap;
完整代码:
不知道,但是使用下面的代码,我可以解决我的问题
class RadioMap:public std::iterator_traits<CartesianLocation>, public Cloneable<RadioMap> {
private:
std::map<const CartesianLocation*, const std::list<RadioSignal<RadioDevice>>*> radioMap;
std::vector<RadioDevice> radioDevices;
public:
void add(const CartesianLocation *location, const std::list<RadioSignal<RadioDevice>> *observedSignals){
radioMap[location] = observedSignals;
}
在这一行,radioMap[location] = observedSignals;
我以这个错误结束
_LIBCPP_TYPE_VIS_ONLY结构上的“二进制表达式无效的操作数('const CartesianLocation'和'const CartesianLocation')”: __x <__y;}};
知道我哪里错了吗?
您没有提供的比较器std::map
,因此使用std::less
。但是std::less
没有的重载CartesianLocation
(CartesianLocation
也没有operator<
),因此会出现错误。
您可以添加operator<
:
struct CartesianLocation
{
//Other stuff
bool operator<(const CartesianLocation& loc2) const
{
//Return true if this is less than loc2
}
};
另一种方法是定义自定义比较器,例如:
struct comp
{
bool operator()(const CartesianLocation& loc1, const CartesianLocation& loc2) const
{
//Compare the 2 locations, return true if loc1 is less than loc2
}
};
然后,您可以将其传递给std::map
:
std::map<CartesianLocation, std::list<RadioSignal<RadioDevice>>, comp> radioMap;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句