I'm using complex numbers for learning design patterns. I'm currently using an abstract class:
namespace abstract{
class complex{
public:
virtual ~complex() = 0;
virtual double re() const = 0;
// some other virtual function
};
};
namespace cartesian{
class complex : public abstract::complex{
public:
complex(){}
~complex(){}
double re() const override{return re_;};
//... other functions
private:
double re_;
double im_;
// other
};
};
namespace polar{
class complex{
/// polar complex numbers....
};
};
I want to being able to write in the main:
cartesian::complex c(1,2);
polar::complex p(3,PI);
exponential::complex q = exp(c) + p;
print(q)
The thing is that I will have to write a lot of assignment operators with forward declarations for each class. So is there a way to make all representations of the complex class the same type, and having just different constructors? Something like pimpl with different pointers for each implementation or something with templates i don't know.