Skip to content

Instantly share code, notes, and snippets.

@willianrschuck
Created September 10, 2019 13:47
Show Gist options
  • Save willianrschuck/ccdee10375e63880f6a2efd050b30c47 to your computer and use it in GitHub Desktop.
Save willianrschuck/ccdee10375e63880f6a2efd050b30c47 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
struct MinhaStruct {
int chave;
};
/*
Os operadores de comparação não são gerados quando a struct é definida.
Ainda é possível as definir por si mesmo.
*/
bool operator==(const MinhaStruct &L, const MinhaStruct &R)
{
return L.chave == R.chave;
}
int main() {
MinhaStruct s1;
MinhaStruct s2;
s1.chave = 1;
s2.chave = 1;
cout << boolalpha << (s1 == s2) << endl;
s1.chave = 8;
cout << boolalpha << (s1 == s2) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment