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
I have been working on unified functionality for types to be passed to a member function.
...By the way, what are you trying to achieve exactly ?
I don't see a const keyword being dropped, where ?
Why ? Your template doesn't include a "const" why the compiler would add it ? Anyway it doesn't make a difference, only the "by value" template overload matches.
You would need to add the const in your (by reference) template, in theory, except it's not working in MQL (limitation not bug).
For sure, you called it explicitly !? An it's always the same template overload which is used because the compiler doesn't have a way to chose between by value or by reference, it always pick the by value one.
However, about your original question "why is it only "const int" that's not working? ". You are right, it's not quite clear why it's only with "const int" it gives an ambiguous call. I checked with C++ and it gives an error in the 3 cases.I don't know if it's by design from MQ developers or a bug. I will ask some explanation.
Well, to my understanding, it gets dropped. Here is the comparison, I was making to conclude this:
Versus:
Yes, I know, I called it explicit, thats on purpose. - Else it wont compile.
But the main question is, why is the const not passed forward to the function template? - Shouldnt it be? - I know, its a copy inside the function and any change would not reflect to the passed parameter.
But why, if this template is available, expanded with "int", not "const int", is it required to have a "int" signature to take in the const declared int variable as parameter?
C/C++ behaves totally different in this regard, I know about that. - But in C/C++, I would know how to design a functions signature to take in all required inputs, which leads me to your next post/question, I will answer there.
By the way, what are you trying to achieve exactly ?
My goal is to have a function signature/function-call, which is able to take in all types, except for enum and bool.
So what I would like to have is a function that can be called with
- pointer
- class-object
- struct-object
- literals/primitives (iE int, datetime, double ...)
- r-values of primitive-types. (iE D'2020.01.01', 0x01, 4, 1.002 and so on)
so that I have one function name, like __func(), and I can pass in any of the above mentioned values.
EDIT:
Also arrays as applicable, of course.
My goal is to have a function signature/function-call, which is able to take in all types, except for enum and bool.
So what I would like to have is a function that can be called with
- pointer
- class-object
- struct-object
- literals/primitives (iE int, datetime, double ...)
- r-values of primitive-types. (iE D'2020.01.01', 0x01, 4, 1.002 and so on)
so that I have one function name, like __func(), and I can pass in any of the above mentioned values.
EDIT:
Also arrays as applicable, of course.
It's impossible currently, too much mql limitations.
Well maybe there is a way, but it will need to be so complicated and hacked that it's not worth it in my opinion.
It's impossible currently, too much mql limitations.
Well maybe there is a way, but it will need to be so complicated and hacked that it's not worth it in my opinion.
It's impossible currently, too much mql limitations.
Well maybe there is a way, but it will need to be so complicated and hacked that it's not worth it in my opinion.
I would like to hear your opinion on this code:
As you can see, I did a cast on the constant variable, so it is required to match the third template. - But, if I dont cast the variable, the compiler cannot select a matching template, and complains about ambiguous call. - But shouldnt this also be the case for the non-const call one line above??
Why does the compiler select the non-reference call for the non-const variable, instead of the reference-call. - And, why does the const variable not match as the non-const variable.
This is (I am quite confident now) obviously an inconsistent behaviour, especially, because it works for pointer, objcets and structs exactly as expected. - I make my claim, this is a bug in the compilers template matching algorithm.
What do you think?
EDIT:
And to proove my point further, if you change the first template like this, and change the call to the __func() as shown below, the compiler suddenly switches over to have issues with the non-const variable. The behaviour now is vice-versa between "int" and "const int".
If you remove the cast operation within the function call, the compiler will complain again. - And it is vice-versa with the const declarations. - The compilers matching for "const" and "non-const" is mixed up.
I would like to hear your opinion on this code:
...I don't have time currently (for some days), I will check when possible (don't hesitate to ask again in case I forget).
I would like to hear your opinion on this code:
This is (I am quite confident now) obviously an inconsistent behaviour, especially, because it works for pointer, objcets and structs exactly as expected. - I make my claim, this is a bug in the compilers template matching algorithm.
What do you think?
I don't have time myself as well but I encountered these kind of problems in compiler matching template methods in template classes as well.
I didn't bother to point it out and isolate the problems like you do, because I think as long as we don't have interfaces in MQL5 all these templates are very limited as well.
I don't have time myself as well but I encountered these kind of problems in compiler matching template methods in template classes as well.
I didn't bother to point it out and isolate the problems like you do, because I think as long as we don't have interfaces in MQL5 all these templates are very limited as well.
I don't have time currently (for some days), I will check when possible (don't hesitate to ask again in case I forget).