You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
dynamic cast for comparison? Are you out of your mind?
I don't care about execution time in this case, the type can be defined in other ways too, e.g. by a virtual override function. The code was written on the spot in 10 minutes to show the principle and is not a working variant
What is the point of CBase? And why should 2 values of the same type be compared?
So you have a semantic error: the notions Comparer and Comparable are jumbled together. The first is a comparer (an independent class), while the second is an interface for the object being compared (i.e. it compares this to another object). This object can inherit this
So you have a semantic mistake. The notions Comparer and Comparable are mixed up. The first one is a Comparer (an independent class) and the second one is an interface to the object being compared (i.e. compares this with another object).
My Number is just the Comparable type, and the interface is the Comparer type, and they are somehow cleverly linked in Sharp too. In this case they work through each other. I'm telling you, it wasn't my aim to copy exactly that structure there. The goal here is to show how one can make a template-based interface which is necessarily inherited from one of the classes being compared. That's the mechanism I saw with you and I liked it.
You have IComparer for some reason inherited from Number, although they are absolutely different entities.
I have Number here by the type of the base class object, well, very roughly, I didn't set a goal to present a working architecture on 100 lines. But everything will inherit from one common ancestor anyway
Here they work through each other.
Number can inherit IComparable interface and it also can return IComparer for its type via separate method.
Number is not really a number, it doesn't even have a value field if you notice. I just called it that... Ok, if something working for me will work out then I'll offer to discuss it, but in the meantime if my example doesn't fit at all just don't bother.
Number is not really a number, it doesn't even have a value field if you notice. I just called it that... OK, if I end up with something workable then I'll offer to discuss it, but in the meantime, if my example doesn't work at all, just leave it out of your head