简体   繁体   中英

Invalid operands to binary expression ('RadioDevice' and 'const RadioDevice')

I stuck badly on this issue, I am trying to find an object in list using find(). Below is the code:

std::vector<RadioDevice> radioDevices;
public:
void add(CartesianLocation location, std::list<RadioSignal<RadioDevice>> observedSignals){
    for(RadioSignal<RadioDevice> radioSignal : observedSignals) {
        if (std::find(radioDevices.begin(),
                      radioDevices.end(),
                      radioSignal.getRadioDevice()) != radioDevices.end()) {
            radioDevices.push_back(radioSignal.getRadioDevice());
        }
    }
}

RadioSignal extends RadioDevice which is an pure abstract class. I am getting below error at if (*__first == __value_) in find()

Invalid operands to binary expression ('RadioDevice' and 'const RadioDevice')

So, assuming you have a class RadioDevice defined as:

class RadioDevice {
public:
  virtual std::string getMacAddress();
  virtual RadioDeviceType getType();
  virtual double getFrequency();
  virtual std::string getIdentifier();
  virtual void setIdentifier(std::string identifier);
  virtual int getTxPower();
};

You'll need to define an operator== for your RadioDevice class. You can do that by adding

bool operator==(const RadioDevice& rhs, const RadioDevice& lhs) {
  return rhs.getIdentifier() == lhs.getIdentifier();
}

but, this assumes that two RadioDevice objects are equal if they have the same identifiers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM