Errors, bugs, questions - page 2272

 
fxsaber:

One is only created. Moreover, in f you will not be able to use T.

This in itself is an error.
template<typename T>
void f() { Print( sizeof( T )); }
struct A { int a; };
void OnStart()
{
        f<int>(); //(1)//нормально
        f<A>();   //(2)//нормально
struct B { int b; };
        f<B>();   //(3)//Error: 'B' - undeclared identifier
}
And what is the fundamental difference between (1)(2) and (3) ???
 
fxsaber:

Moreover, in f you will not be able to use T. All in all, the situation is obvious to me.

Moreover, violated your prohibition to use T in f

template<typename T>
void f() { class T; Print(__FUNCSIG__, ":" , sizeof(T)); }
template<typename T1, typename T2>
void g() { class T1 { T2 x; } a; f<T1>(); }
void OnStart()
{
class A {};
        g<A,int   >();
        g<A,double>();
}

As you can see it compiles without errors, and the fact that the result is absurd is not important as long as everything is "explainable".

 
Hello, everyone. Help. Can't make gold trades, everything is working, but it's the trades I can't make. Here are screenshots of what it looks like.
 

What is the sacred meaning of this code, why did they cram it into the standard library at all?

   if(IsStopped(__FUNCTION__))
      return(false);

Now it is impossible to use functions of closing positions or orders from the standard library in OnDeanite, for example with REASON_REMOVE

 
Stanislav Dray:

What is the sacred meaning of this code, why did they cram it into the standard library at all?

Now you can't use functions to close positions or orders from the standard library in OnDynit, for example with REASON_REMOVE.

Yes, that's a bug.

 
A100:

Moreover, I violated your prohibition to use T in f

As you see, it compiles without errors, and the fact that the result is absurd is not important - the main thing is that everything is "explainable".

You don't quite understand what templates are. They are similar to macros only with certain features.

Here is the code

template<typename T>
void f() { class T{ MqlTick a; }; Print(__FUNCSIG__, ":" , sizeof(T)); }
template<typename T1, typename T2>
void g() { class T1 { T2 x; } a; f<T1>(); }
void OnStart()
{
class A {};
        g<A,int   >();
        g<A,double>();
}

.

void f<A>():68
void f<A>():68

That's because T is a setup, like macros, only with certain caveats. What we have in the end is that a signature is created. Inside the function nobody knows about A which is substituted for T in the function. But you define this A inside, so no further compilation error occurs. I inserted MqlTick inside to show that this A has nothing to do with other classes of the same name.

In short, the intraclasses in MQL5 are not visible outside the parent function. Only the name of the type as a class is passed as T. In this case the name has no reference to the parent function.

I.e. everything is quite logically explainable. It's not a bug, but such a limited implementation.


Maybe at a job interview a C++ programmer would say that this is impossible.

template<typename T>
void f() { class T{}; }


MQL5 is quite possible.

 
fxsaber:

You don't quite understand what patterns are.

fxsaber:

ZS Probably a C++ programmer at a job interview will tell you that this is impossible

If you think that this is impossible in C++ it means that it's not me but you who doesn't understand what templates are and how they work... all the more that you can't tell a sloppy implementation from a constrained one

 
A100:

If you think such a thing is impossible in C++ - that means it's not me, but you don't understand what templates are and how they work... all the more so that you can't tell a sloppy implementation from a bounded one

Read the first word of the sentence you give your comment on. My understanding of templates and macros in MQL5 is such that I realise without trying to compile that your examples won't compile in MQL5. C++ - I don't know, that doesn't prevent it.


I would be grateful if you could show how C++ reacts to this code

Forum on trading, automated trading systems and strategy testing

Bugs, bugs, questions

fxsaber, 2018.09.03 07:16

ZS Probably a C++ programmer at a job interview will tell you that this is impossible

template<typename T>
void f() { class T{}; }
 
fxsaber:

I'd appreciate it if you could show me how C++ reacts to this code.

The reaction is the same as in MQL. Why should it be different? A template is a template
 
fxsaber:

You don't really understand what templates are. And they are akin to macros, only with some tricks.

Yes, this example will not compile on the pluses

error: declaration of 'struct f()::T' shadows template param template<typename T>

but even if it compiled, the result would surprise you because the class name would just be "T".

if it is different in mql, this is incorrect