mercredi 17 juin 2020

Is there a way to modify 'operator->' so that 'z->im' returns imaginary part of complex number

I have a struct Cmplx which models complex numbers.

class Cmplx{
  double x;
  double y;
 public:
  Cmplx(int X, int Y){x = X; y = Y;}
  double& operator->(...){...}
}

I need to implement the operator, such that

int main(){
Cmlpx z(1,2);
z->im = 5;
z->re = 2;
}

Changes my complex number into (2,5); I know how to do it when im and re are strings, but have no idea how to do it like this.

Aucun commentaire:

Enregistrer un commentaire