Can anyone explain to me what I'm doing wrong here?All that I'm trying to do is to use the idea of polymorphism for operators, in special the operator++. I want to have a result something like this:
I found it difficult to come up with a descriptive enough title for this scenario so I'll let the code do most of the talking.
I commonly come across the need to create arrays or vectors of polymorphic objects. I'd usually prefer to use references, rather than smart pointers, to the base class because they tend to be simpler.
I want to store Particle objects in a vector object, so I can access it later. These particles (Electrons and Protons) are inherited from the Particle class which contains a toString() virtual method. This toString() method is then overrided in Electron and Proton classes.
One limitation of implementing polymorphism in a language via monomorphisation (and monomorphisation only) is that you lose the ability to support polymorphic recursion (e.g. see rust-lang #4287).
I have a class Price that encapsulates an Int. I also would like it to have constructors for Num and Str. I thought I could do this by making Price::new a multi method with various type constraints, but this isn't the behavior I expected. It looks like Price.new is skipping...