Created
October 4, 2014 19:52
-
-
Save marcoscastro/cc43715ac759413f5128 to your computer and use it in GitHub Desktop.
Aula 41 - Sobrecarga do operador +
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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