I am trying to overload + operator in the following simple code. However, every time I am getting the same error as *Process finished with exit code -1073741819 (0xC0000005)* and the code does not output anything. What exactly is the problem which is causing this runtime memory error?

```
#include <iostream>
using namespace std;
class Complex{
private:
int real;
int imaginary;
public:
Complex() : real(0), imaginary(0){}
void getData(int real, int imaginary);
Complex* operator +(Complex Obj);
void showData();
};
void Complex :: getData(int real, int imaginary){
this->real = real;
this->imaginary = imaginary;
}
Complex* Complex :: operator+(Complex Obj){
Complex* temp;
temp->real += real + Obj.real;
temp->imaginary += imaginary + Obj.imaginary;
return temp;
}
void Complex :: showData(){
cout << real << " + " << imaginary << "i";
}
int main(){
Complex Number1, Number2;
int real, imaginary;
cout << "Enter real and imaginary of first complex number" << endl;
cin >> real >> imaginary;
Number1.getData(real, imaginary);
cout << "Enter real and imaginary of second complex number" << endl;
cin >> real >> imaginary;
Number2.getData(real, imaginary);
Complex *Number3;
Number3 = Number1 + Number2;
Number3->showData();
return 0;
}
```

asked on Stack Overflow Jan 30, 2020 by Arun Suryan

User contributions licensed under CC BY-SA 3.0