Overloading + Operator results in the exit code -1073741819 (0xC0000005)


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{
    int real;
    int imaginary;
    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;

return 0;
asked on Stack Overflow Jan 30, 2020 by Pikachu

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0