How do I dynamically allocate memory to a polymorphic data type?
问题 I have a set class that can polymorphically hold and manage anything of type Multinumber. This can be an object of type Pair, Rational, or Complex. The problem that I am running into is that this class requires dynamic memory management and in many cases, such as the function below, I don't know what type to allocate. Since the set is type agnostic, I can't know if I am supposed to do Multinumber* var=new Complex, Rational, or Pair. Is there any way to check the type of what I am adding first