I am trying to make a class Complex ( complex numbers of form z=a+ib m where a= _re and b=_im) and I need to create and constructor with 2 parametres(double,double). The _re and _im are 2 double pointers , and I don't know how to point them to a value. Here is the code , I can't modify the Class because is a school project .
#include <iostream>
#include <cmath>
using namespace std;
class Complex {
private:
double* _re;
double* _im;
public:
Complex();
Complex(double, double);
void Display();
};
Complex::Complex()
{
_re = 0;
_im = 0;
cout << "Complex::Complex()" << endl;
}
Complex::Complex(double re, double im)
{
double* _re = new double;
_re = &re;
double* _im = new double;
_im = &im;
cout << "Complex::Complex(double re,double im)" << endl;
}
void Complex::Display()
{
int nr = 1;
cout << "z" << nr << "= " << *_re << "+i* " << *_im << endl; nr++;
}
int main()
{
Complex z1(2,3);
z1.Display();
return 0;
}