Typing question - page 5

 
Ilya Malev:
P.S., ah, i.e. you wanted to overload a binary operator as a unary one (2-ary as 1-ary), then yes, of course not a date. The only exception is [].

Yes, in MQL it is rigidly prescribed what and how to overload, in C++, it does not matter what to overload, you will call it the same way - if you overload ^ as unary, you will use it as unary in the future

 
Igor Makanu:

Yes, in MQL it's strictly specified what and how to overload, in C++ it doesn't matter what to overload, you can call it the same way - you overload ^ as unary and you will use it as unary in the future.

Yes, it seems there are still many limitations in mql, so there is room for improvement :)

I would also like the possibility to overload binary operations as unary (and vice versa).

Since in any case, when overloading their original meaning is often lost, respectively, the logic of use is no longer associated with this meaning. It would be logical to allow it.

 
Ilya Malev:

Yes, it looks like there are still a lot of restrictions in mql, there's room for improvement :)

There are a lot of them, and these limitations appear, then disappear, then five... it seems that developers sometimes change the development environment ))))

As an example, in the Help, in the section overloading operations (operator) examples of work with matrices now are not compiled, while I know that they used to work, now there is a check for the type of parameters that participate in the overloading of operations, i.e. if I have

int operator*(const int) then int operator*(int) will not compile and there was such example in the help, which stopped compiling

 
Ilya Malev:

Dear programmers, I've been puzzling over a question for a long time. Is it possible to somehow contrive and make implicit typing of function's return value? So that the class method would return a value of a different type with the external identity of calling the methods.

And may I ask: for what purposes do you need it? Can't you build a starship without it?

 
Vasiliy Sokolov:

May I ask what you need it for? Can't you build a starship without it?

And may I ask: What is your interest in it?

 

And by the way, it's not even an overload of the return type.

In general, this idea is very far from being feasible.

 
Vasiliy Sokolov:

May I ask what you need it for? Can't you build a starship without it?

I was also critical at first, but then I thought I could use it for myself too:

class Point {
public:
   double price;
   long time;
   operator double()const {return price;}
   operator long()const {return time;}
};

class Array {
   Point p[3] = {{0,1}, {2,3}, {4,5}};
public:
   const Point &operator[](unsigned i) {return p[i];}
};

void start()
{
   Array a;
   double d = a[2];  // d == 4
   long t = a[2];    // t == 5
}
 
Dmitry Fedoseev:

And by the way, it's not even an overload of the return type.

Captain Obvious to the resque?

 
Ilya Malev:

Captain Obvious to the resque?

Shift+Alt if you've forgotten.

 
C# has explicit and implicit conversions. It seems to be convenient sugar, but very implicit and IntelliSense will be silent. In a month you will forget what class can be converted to what. An OOP game in general, but nice.
Reason: