OOP, templates and macros in mql5, subtleties and uses - page 11

 
TheXpert:

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

 
Ilya Malev:

What is the point of CBase? And why should 2 values of the same type be compared?

Yes, you don't need CBase here at all. You have IComparer for some reason inherited from Number, although they are absolutely different entities. Comparer is not an interface for Number, it's an independent object that accepts two numbers. So your Comparer should be just IComparer<T1,T2> and without any Number and CBase
 
Right, another shitcoder with an ego.
 
Self-importance is just when someone gets on a branch and starts throwing poo. Very important poop. I simply wrote to the comrade (not you) with whom we were discussing the topic of templates, how I see such an implementation.
 
Ilya Malev:

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

 
Alexey Navoykov:

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.

 
Alexey Navoykov:
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

 
Ilya Malev:

Here they work through each other.

But it doesn't do that. You can't inherit different entities from each other. Number can inherit the IComparable interface, and it can also return IComparer for its type in a separate method.
 
Alexey Navoykov:
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.

 
Ilya Malev:

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

OK. But you should think about abstract methods. Without them it looks very unreliable.
Reason: