Skip to content

Instantly share code, notes, and snippets.

@marcoscastro
Created October 4, 2014 19:52
Show Gist options
  • Select an option

  • Save marcoscastro/cc43715ac759413f5128 to your computer and use it in GitHub Desktop.

Select an option

Save marcoscastro/cc43715ac759413f5128 to your computer and use it in GitHub Desktop.
Aula 41 - Sobrecarga do operador +
// Sobrecarga do operador +
#include <iostream>
using namespace std;
class Complexo
{
public:
int real, imag;
Complexo(int real, int imag)
{
this->real = real;
this->imag = imag;
}
Complexo operator+(Complexo& c)
{
return Complexo(this->real + c.real, this->imag + c.imag);
}
};
int main(int argc, char *argv[])
{
Complexo c1(1, 2), c2(3, 4);
Complexo c3 = c1 + c2;
//Complexo c3 = c1.operator+(c2);
cout << "Parte real: " << c3.real << endl;
cout << "Parte imaginaria: " << c3.imag << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment