lundi 29 avril 2019

error: invalid operands to binary expression ('Entry' and 'Entry') [duplicate]

This question already has an answer here:

I wrote a program that compares two entries using a structure. It returns true if they are the same ,and returns false if they are different. But when I run the program, it gives me the error: invalid operands to binary expression ('Entry' and 'Entry') if (e1 == e2).

It seems like it's not possible to use the comparison operator for structures?

My code:

#include <iostream>
using namespace std;

struct Entry
{
  string firstname;
  string lastname;
  char dorm;
  int age;
};

Entry equal(Entry e1, Entry e2)
{
  if (e1 == e2)
    return true
  else
    return false
}

int main()
{
  Entry e1 = {"Harry", "Potter", 'C', 25};
  Entry e2 = {"James", "Bond", 'D', 40};

  if (equal(e1, e2))
    cout << "same" << endl;
  else
    cout << "different" << endl;

  return 0;
}

Aucun commentaire:

Enregistrer un commentaire