I am a C++ noob, so please don’t mind if you find this question silly
I am declaring map in C++ a below:
std::map<CartesianLocation, std::list<RadioSignal<RadioDevice>>> radioMap;
Full code:
Don't know but using below code, I could able to solve my issue
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;
}
On this line radioMap[location] = observedSignals;
I am ended with this error
“Invalid operands to binary expression ('const CartesianLocation' and 'const CartesianLocation’)” on struct _LIBCPP_TYPE_VIS_ONLY less : binary_function<_Tp, _Tp, bool> { _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const {return __x < __y;} };
Any idea where I may be wrong?
You are not providing a comparator for std::map
, and so it uses std::less
. But std::less
doesn't have an overload for CartesianLocation
(and CartesianLocation
doesn't have an operator<
), so you get an error.
You can add an operator<
:
struct CartesianLocation
{
//Other stuff
bool operator<(const CartesianLocation& loc2) const
{
//Return true if this is less than loc2
}
};
Another way is to define a custom comparator, for example:
struct comp
{
bool operator()(const CartesianLocation& loc1, const CartesianLocation& loc2) const
{
//Compare the 2 locations, return true if loc1 is less than loc2
}
};
Then you can pass it to std::map
:
std::map<CartesianLocation, std::list<RadioSignal<RadioDevice>>, comp> radioMap;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With