#include<iostream> #include<stdlib.h> using namespace std; class Complex{ private : int real,imaginary; static int count; public : Complex(int r,int im){ real=r; imaginary=im; Complex::count++; } Complex(){ real=imaginary=0; Complex::count++; } ~Complex(){ cout<<"Destructor called for Complex"<<Complex::count<<endl; Complex::count--; } void print(){ cout<<"Real : "<<real<<endl; cout<<"Imaginary: "<<imaginary<<endl; } void read(int r,int im){ real=r; imaginary=im; } int getReal(){ return real; } int getImaginary(){ return imaginary; } Complex operator +(Complex &c){ Complex c1; c1.read(c.getReal()+real,c.getImaginary()+imaginary); return c1; } }; int Complex::count=0; int main(){ cout<<"All is well"<<endl; Complex c(100,34); Complex c2=c+c; c.print(); c2.print(); return 0; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)