Errors, bugs, questions - page 2869

 
A100:

You have a syntax error - give an example of working code with (typename) in brackets. You might as well write (OnStart) in brackets

Well, there is no syntax error

typename(J)

But do you already consider this code a syntax error?

(typename)J

When a type conversion principle is supposed to work here, and Help allows both variants.

 
Roman:

Like this, there's no syntax error.

Does this count as a syntax error?

When the principle of type conversion is supposed to work here, and the help allows for both.

template<typename T>

typename is not a type, it is a keyword. In this case, the type is T. The conversion is to a type, not to the keyword.

The philosophical justification is not appropriate here. Although if MQL were an abstract language, we could probably resort to casting to the keyword and it would move up to the 1st place in the ranking

 
A100:

typename is not a type, it is a keyword. In this case, the type is T. The conversion is to a type, not to a keyword

Philosophical justification is not appropriate here. Although, if MQL were an abstract language, we could probably cast it to the keyword, and it would move up to the 1st place in the rating

I understand that typename is not a type.
But in this case, we're getting a transformation.
We obtain its type from a constant.
Maybethis is not correct in syntax? But it works.

#define  A '+'

typename(A)
 
Roman:

I understand that typename is not a type.
But in this case, we get a transformation.
From a constant, we get its type.
Maybethis is not the right syntax? But it works.

It works, but not the way you think it will. You do not get a type but a string. I wanted to show you this by example, but I got an error below.

But it doesn't mean that you're right - just another error of the compiler.

 
Compilation error:
void OnStart()
{
    Print(typename("ushort"));      //(1) нормально
    Print(typename(typename('+'))); //(2) Error: 'typename' - unexpected token
}

What is the difference between (1) and (2) ? Dear developers - maybe Roman is right and now typename returns type?

The result was expected: string

 
A100:

It works, but not in the way you imagine. You do not get a type, but a string. I wanted to show it with an example, but I got an error:

How it is not a type?
It is a type, not a string.
ushort is not a string.

#define   A '+'

void OnStart()
{
   Print(typename(A));
   Print(typename("string"));
}
2020.10.09 01:45:54.402 TestScript (MNQZ20,M1)  ushort
2020.10.09 01:45:54.402 TestScript (MNQZ20,M1)  string
 
Roman:

How is it not a type?
Just getting a type, not a string.
Ushort is not a string.

You do not get ushort, but "ushort". Do you understand the difference? If not, read the documentation before understanding.

Although it would be cool to get a real ushort!

 
A100:

You do not get ushort, but "ushort". Do you understand the difference? If not, read the documentation to understand

So Print() already prints it as "ushort" with a string literal.
What does it have to do with it? The very fact that typename returns a type name!

 
Roman:

So this already prints Print() as "ushort" string literal.
What does that have to do with it? The very fact that typename returns a type name!

Have you read the documentation at the link? There is an example there, too. Unfortunately, my example failed.

 
A100:

Have you read the documentation on the link?

What does it have to do with templates?
If the usage syntax is not for a template, in this case.

Reason: